Professional Documents
Culture Documents
If Elif Else, While, In, Lamda, Class
If Elif Else, While, In, Lamda, Class
[5]:
l1=[4,5,315,61]
In [6]:
if (l1[0]>l1[1]) & (l1[0]>l1[2]) & (l1[0]>l1[3]):
print(l1[0],"value is greatest")
print(l1[1],"value is great")
print(l1[2],"value is greatest")
else:
print(l1[3],"is greatest")
In [7]:
max(l1)
Out[7]: 315
In [8]:
min(l1)
Out[8]: 4
In [9]:
l1.sort()
In [10]:
l1
In [18]:
s1={'k1':10,'k2':20,'k3':30}
In [19]:
if s1['k3'] ==30:
s1['k3']=s1['k3']+100
In [20]:
s1
In [12]:
i=1
while i<=10:
print(i)
i=i+1
10
In [13]:
print(i)
11
In [11]:
z=13
y=14
x=10
In [14]:
if (z>y) & (z>x):
print(x,"first is greatest")
print(y,"second is greatest")
else:
print(z,"third is greatest")
14 second is greatest
In [23]:
i=1
n=23
while i<=10:
print(n,"*",i,"=",n*i)
i=i+1
23 * 1 = 23
23 * 2 = 46
23 * 3 = 69
23 * 4 = 92
23 * 5 = 115
23 * 6 = 138
23 * 7 = 161
23 * 8 = 184
23 * 9 = 207
23 * 10 = 230
In [11]:
l1=['Mango','Banana','Pineapple','Grapes']
l2=['Blue','Green','Blue','Yellow']
l3=['Apple','Samsung','Nokia','One Plus']
In [12]:
for i in l1:
print(i)
Mango
Banana
Pineapple
Grapes
In [13]:
for i in l2:
print(i)
Blue
Green
Blue
Yellow
In [15]:
for i in l1:
for j in l2:
for k in l3:
print(i,j,k)
In [16]:
s1=['kalli','Gandi','Sadali','Po-Po karne wali']
s2=['doddo']
In [17]:
for i in s1:
for j in s2:
print(i,j)
kalli doddo
Gandi doddo
Sadali doddo
In [20]:
def nu(x):
if x%2==0:
else:
In [24]:
nu(7032)
In [31]:
s1=("hey this is a program that can convert lower case into upper case and THESE ARE UPPER cASE")
In [49]:
f2=s1.upper()
In [50]:
f1=s1.lower()
In [51]:
s1.isupper()
Out[51]: False
In [52]:
s1.islower()
Out[52]: False
In [53]:
f1
Out[53]: 'hey this is a program that can convert lower case into upper case and these are upper case'
In [56]:
f2.isupper()
Out[56]: True
In [55]:
f1.islower()
Out[55]: True
In [9]:
l1=(5,51,65,5,6,518,1,65,6,56,1,68,9,1,68,8,6,86,87648,86,646,98,3,9,13,49,531,7,6,31,8,62,18,2,61,619,615,611,10)
In [10]:
even=list(filter(lambda x:(x%2==0),l1))
odd=list(filter(lambda x:(x%2!=0),l1))
print("even =",even)
print("odd =",odd)
even = [6, 518, 6, 56, 68, 68, 8, 6, 86, 87648, 86, 646, 98, 6, 8, 62, 18, 2, 10]
odd = [5, 51, 65, 5, 1, 65, 1, 9, 1, 3, 9, 13, 49, 531, 7, 31, 61, 619, 615, 611]
In [11]:
double=list(map(lambda x: x*2,l1))
print(double)
[10, 102, 130, 10, 12, 1036, 2, 130, 12, 112, 2, 136, 18, 2, 136, 16, 12, 172, 175296, 172, 1292, 196, 6, 18, 26, 98, 1062, 14, 12, 62, 16, 124, 36, 4, 122, 1238, 1230, 1222, 20]
In [12]:
from functools import reduce
In [13]:
sum=reduce(lambda x,y: x+y,l1)
print(sum)
92158
In [14]:
sume=reduce(lambda x,y: x+y,even)
print(sume)
89406
In [16]:
sumo=reduce(lambda x,y: x+y,odd)
print(sumo)
2752
In [18]:
sume+sumo
Out[18]: 92158
In [46]:
class Phone:
def __init__(self,games,screen,ram,rom):
self.games=games
self.screen=screen
self.ram=ram
self.rom=rom
def Phone_features(self):
In [47]:
p1 = Phone("BGMI","7 Inches","4gb","128gb")
In [49]:
p1.Phone_features()
In [70]:
class Bgmi(Phone):
def __init__(self,games,screen,ram,rom,fire,reload,aim):
super(). __init__(games,screen,ram,rom)
self.fire=fire
self.reload=reload
self.aim=aim
def bgmi_features(self):
In [73]:
b1 = Bgmi("Bgmi","7.2inches","4gb","1.8gb",542,30,8)
In [74]:
b1.bgmi_features()
In [75]:
b1.Phone_features()
In [ ]: