Python: Conditioning, Loops
#using if statement
x=20
if(x>=18):
print('You are welcome')
print('Move on')
#using if with else
x=13
if(x>18):
print('You are welcome')
else:
print('you are not allowed')
print('Move on')
#using if with elif(else if) and else statement
x=18
if(x>18):
print('Your are welcome in party')
elif(x==18):
print('you are welcome in lounge')
else:
print('you are welcome in kidparty')
print('Move on')
#using or operator
x=30
if(x>30)or(x<30):
print('You are unsuitable')
else:
print('You are not suitable')
print('Thank you')
#using and operator
x=25
if(x>20)and(x<30):
print('You are in goldenzone')
else:
print('You are not in golden zone')
print('thank YOU')
#loop for and while
range(3)
range(10,15)#output should be [10,11,12,13,14]
square=['red','blue','yellow','green','brown']
for i in range(0,5):
square[i]='white'
print(square)
square1=['blue','red','green','yellow','grey']
for square1 in square1:
print(square1)
square1=['red','yellow','blue']
for i,square in enumerate(square1):
print(square, i)
#using while loop
list1=[14,15,19,32,25,35,23,17]
newlist1=[]
i=0
while(list1[i]>19):
newlist1.append(list1[i])
i=i+1
print(newlist1)
dates=[1991,1992,1993]
for year in dates:
print(year)
Comments
Post a Comment