You are on page 1of 21

46.

BASIC

print("Hello")

a=10

print(type(a))

b=input("enter value of A: ")

print("A: ",b)

47. DATATYPES

a=10

print(type(a))

c=2+4j

print(type(c))

b=10.4

print(type(b))

d=True

print(type(d))

f={'a','b','c'}

print(type(f))

x={"key":"value"}

print(type(x))
lt=[1,2,3]

print(type(lt))

y="ECAM"

print(type(y))

z=(1,2,3)

print(type(z))

48.OPERATORS

x=10

y=20

z=x+y

print("answer:",z)

x+=5

print("x:",x)

x=5

y=3

print(x==y)

x=["ab","ef"]

y=["ab","ef"]

z=x
print(z)

x=["ab","ef"]

y=["cd","gi"]

print(x is y)

x=["ab","ef"]

print("do" in x)

49. OPERATIONS IN LIST

#printing list

l1=[1,2,3,4,5,6]

l2=["apple","kiwi"]

print("int list:",l1)

print("stringlist:",l2)

#list construction

l1= list(("apple","kiwi"))

print("\nl1:",l1)

#duplicate list

l1=[1,2,3,4,5,6,1,2,3]

print("\nduplicate value:",l1)
#list slicing

l1=[1,2,3,4,5,6]

print("\ncurrent list:",l1)

print("index 1 value:",l1[1])

print("index 1to4:",l1[1:4])

print("index till 4:",l1[:4])

print("last value:",l1[-1])

#list item change

x=["ab","cd","ef"]

print("\ncurrent list:",x)

x[0:1]=["gh","pq"]

print("updated list:",x)

#insert into list

l1=[1,2,3,4,5]

print("\n current list:",l1)

l1.insert(2,"Barkha")

print("updated list:",l1)

#extend list

l1=[1,2,3,4,5,]

l2=['A','B','C']

l1.extend(l2)

print("\n",l1)

#remove method

l1=[1,2,3,4,5]
print("\n",l1)

l1.remove(3)

print(l1)

#pop method

l1=[1,2,3,4,5]

l1.pop()

print("\n",l1)

#delete method

l1 = [1, 2, 3, 4, 5, 6]

print(l1)

del l1[3]

print(l1)

#clear method

l1=[1,2,3,4,5]

print("\n",l1)

l1.clear()

print(l1)

50. TUPLE

#creatinng a tuple

t1=("ab","cd",1,2,3,4,2,10.5)
print(t1)

#checking the length of tuple

t2=(1,2,3,4,5)

print("\n")

print(len(t2))

#access the value using index

t1=("ab","cd",1,2,3,4,2,10.5)

print("\nindex 1 value:",t1[1])

#accessing value between index

t1=("ab","cd",1,2,3,4,2,10.5)

print("\n index 1 to 4:",t1[1:4])

#printing last value

t1=("ab","cd",1,2,3,4,2,10.5)

print("\n last value:",t1[-1])

print("till 4:",t1[:4])

#convereting tuple into list

t1=("ab","cd",1,2,3,4,2,10.5)

x=list(t1)

print("\n after convert:",x)

#tuple constructer

t3=tuple(("cd","ef"))

print("\n")

print(t3)
#add item after converting tuple into list

print("\n")

y=("cd","ef","gi")

print(y)

print(type(y))

z=list(y)

print(z)

print(type(z))

z[1]="BARKHA"

print(z)

d=tuple(z)

print(d)

print(type(d))

#for loop in tuple

print("\n")

t5=("apple","kiwi")

for i in t5:

print(i)

#while loop i tuple

print("\n")

t5=("apple","kiwi")

i=0

while i<len(t5):

print(t5[i])

i=i+1

else:

print("loop end")
#compare tuple

print("\n")

tuple1=(1,2,3)

tuple2=(1,2,4)

print(tuple1==tuple2)

print(tuple1<tuple2)

print(tuple1>tuple2)

51. DICTIONARY

#creation of dictionary

d1={1:"Apple",2:"Mango",'A':'B'}

print(d1,"\n")

# list into dictionary store

d2={1:"Python",2:"Java","Fruit":["Apple","Kiwi"]}

print(d2,"\n")

# tuple into dictionary store

d2={1:"Python",2:"Java","Fruit":("Apple","Kiwi")}

print(d2,"\n")

#Access the value of dictionary

d1={1:"Apple",2:"Kiwi",'A':'B'}

print(d1)

x=d1[2]
print(x,"\n")

#Access the value using get()

d1={1:"Apple",2:"Kiwi",'A':'B'}

y=d1.get(1)

print(y,"\n")

#Access the item using item()

d1={1:"Apple",2:"Kiwi",'A':'B'}

z=d1.items()

print(z,"\n")

#change the value

d1={1:"Apple",2:"Kiwi",'A':'B'}

d1[2]="Orange"

print("update dictionary :",d1,"\n")

#chnage the value ( by update function)

d1={1:"Apple",2:"Kiwi",'A':'B'}

d1.update({2:"Banana"})

print(d1,"\n")

#remove the value ( using pop method)

d1={1:"Apple",2:"Kiwi",'A':'B'}

print(d1)

d1.pop(2)

print(d1)

d1.popitem()

print(d1,"\n")
#delet the value

d1={1:"Apple",2:"Kiwi",'A':'B'}

print(d1)

del d1[1]

print(d1,"\n")

#clear method

d1={1:"Apple",2:"Kiwi",'A':'B'}

d1.clear()

print("update dictionary:",d1,"\n")

#Access the only key in dictionary

d1={1:"Apple",2:"Kiwi",'A':'B'}

print(d1)

K=d1.keys()

print(K)

52.IF & IF ELSE

#if statement

var=10

if(var==10):

print("value is 10")

print("Bye")
#ifelse statement

a=int(input("enter value of A:"))

b=int(input("enter value of B:"))

if a<b:

print("b is greater")

else:

print("a is greater")

53. IF LADDER

p=int(input("enter your percentage:"))

if p>=70:

print("distinct")

elif p>=65 and p<70:

print("first class")

elif p>=60 and p<65:

print("second class")

else:

print("FAIL")
54. NESTED IF

num = 15

if num >= 0:

if num == 0:

print("Zero")

else:

print("Positive number")

else:

print("Negative number")

55. WHILE

sum=0

n=int(input("N:"))

while n>0:

sum=sum+n

n-=1

print("Sum:",sum)

print("BYE")
56. FOR

numbers = [1,2,3,4,5,6,7,8,9]

sum_ = 0

for num in numbers:

sum_ = sum_ + num

print("The sum of squares is: ", sum_)

57. STAR(RANGE)

rows=5

for i in range(rows):

for space in range(rows,i,-1):

print(end=" ")

for j in range(0,i+1):

j+=1

print("*",end=" ")

print()
58. BCP

#break statement

numbers = [10, 40, 120, 230]

for i in numbers:

if i > 100:

break

print('current number', i,"\n")

#continue statement

numbers = [2, 3, 11, 7]

for i in numbers:

print('Current Number is', i)

if i > 10:

continue

square = i * i

print('Square of a current number is', square,"\n")

#pass statement

months = ['January', 'June', 'March', 'April']

for mon in months:

pass

print(months)
59. STRING

#cretaing a string

a="I am Abhishek"

print(a,"\n")

#adding in string

a="Hello"

b="Python"

print("update string:",a+b,"\n")

#slicing in string

a="Hello Python"

print("Index 1:",a[1],"\n")

#capitalize function

a="hello python"

x=a.capitalize()

print(x,"\n")

#casefold function

a="HELLO PYTHON"

x=a.casefold()

print(x,"\n")

#center function

a="Pyhton"

print(a)

x=a.center(20)
print(x,"\n")

#count function

a="Anime is real life"

x=a.count("Anime")

print(x,"\n")

#comare string

str1="A"

str2="B"

result=str1<str2

print(result)

60. FUNCTION

#inbuild function

print("\n")

#range

l = [10, 20, 30, 40]

for i in range(len(l)):

print(l[i], end=" ")

print("\n")

#round()

x=round(53.7865,2)
print(x,"\n")

#user define function

#1 create function

def myfunction():

print("hello\n")

#2calling function

myfunction()

#3 function with one argument

def myfunction(a):

print("A:",a,"\n")

myfunction(10)

#4function with multiple argument

def myfunction(a,b):

print ("A:",a)

print("B:",b,"\n")

myfunction(10,20)

#5function with keyword arguments

def myfunction(child3,child2,child1):

print("youngest child is:"+child3,"\n")

myfunction(child1="BARKHA",child2="AYUSH",child3="MADHAV")

#default parameter value

def myfunction(state="Gujrat"):

print("I am from:"+state)

myfunction("Rajasthan")
myfunction("Punjab")

myfunction()

print("\n")

#passing a list into function

def myfunction(fruit):

for i in fruit:

print(i)

f=["Apple","Mango","Orange"]

myfunction(f)

print("\n")

#return value from function

def myfunction(x):

return 5*x

print(myfunction(3))

print(myfunction(4))

print(myfunction(5))

print("\n")

#recursion function

def fact(x):

if x==1:

return 1

else:

return(x*fact(x-1))

num=int(input("num:"))

print("the fact of",num,"is:",fact(num),"\n")


#LAMBDA function

x=lambda a:a+10

print(x(5))

y=lambda a,b:a*b

print(y(5,10))

61. G & L VARIABLE

#global variable

z=25

def myfunction():

global z

print(z)

myfunction()

print(z)

#local variable

def sum(x,y):

sum=x+y

return sum

print(sum(5,10))

print(x)
62. RANDOM MODULE

#import random

#1choice()

from random import choice

l1=[1,2,3,4,5,6]

print(choice(l1))

#2randit()

from random import randint

otp=randint(100000,999999)

print("your otp:",otp)

#shuffle()

from random import shuffle

l2=["Apple","Banana","Mango"]

x=shuffle(l2)

print(l2)

63. MATH MODULE


import math
#factorial

print(math.factorial(5))

#ceil

print(math.ceil(2.4))

#floor

print(math.floor(2.4))

#sqrt

print(math.sqrt(2))

You might also like