Control Structure
Control Structure
#4.if..else
x=int(input("enter the number"))
if x>18:
print("YOU ARE ELIGIBLE TO VOTE")
else :
print("YOU ARE NOT ELIGIBLE TO VOTE")
........................................................................................................
#5.if..elif..else
age=int(input(" enter the number "))
if age<3:
print(" child NEED NOT TO PAY ")
elif age>3 and age<60: # age is 3-59
print(" YOU NEED TO PAY full amount ")
else:
print("YOU ARE SENIOR CITIZEN PAY just 40% OF TICKET")
#6.nested if
n=int(input(" enter the number "))
if n>90:
if n<=100: #91-100
print(" A GRADE")
if n>80:
if n<=90: #81 - 90
print(" B GRADE ")
if n>60:
if n<=80: #61 - 80
print(" C GRADE ")
if n>=40:
if n<=60: #40 - 60
print(" D GRADE ")
else:
print("SORRY,YOU ARE FAIL")
print()
............................................................................................
#7.elif ladder
n=int(input(" enter the number "))
if n>90 and n<=100:
print(" A GRADE")
elif n>80 and n<=90:
print(" B GRADE ")
elif n>60 and n<=80:
print(" C GRADE ")
elif n>40 and n<=60:
print(" D GRADE ")
else:
print("SORRY,YOU ARE FAIL")
print()
................................................................................................
#8. for()ex.1
for i in range(10): #by default series start from 0 ,here 10 is exclusive so 10-1=9
print(i,end=' \t ')
print()
#O/P- 0 1 2 3 4 5 6 7 8 9
.................................................................................................
#9.for() loop ex.2
for i in range(5,50): #here series start from 5 ,50 is exclusive so 50-1=49
print(i,end=' ') #o/p : 5 6 7 8 .....49
print()
print()
................................................................................................
#10.for() loop ex.3
for i in range(0,99,4): #here series start from 0 and 99 is exclusive so end value is not 99-1=98 or 99-4=95
print()
print()
................................................................................................
………………………………………………………………………………………………
#12.while() loop
i=5 # i is start value
print(i,end=' ')
i=i+3 # updation : here i++ will not work because unary operator are not accepted
...............................................................................................
14.break statements
list=[1,3,6,-5,7,8]
print("Total no.of item in list",len(list))
for i in list:
if i<0:
break
else:
print(i)
print()
print()
print()
15.continue statements
list=[1,3,6,-5,7,8]
print("Total no.of item in list",len(list))
for i in range(len(list)):
print(list[i],end=' ')
print(" \n..............................***************............... " )
for i in list:
if i<0:
continue
else:
print(i)
16.pass statements
for i in range(5):
pass
print(" pass statement treated as a place holder " )
17.while ..else
i=9
while(i<5):
print(i,end=' ')
i+=1
else:
print("else statement")
18.for …else
for i in range (30 , 4 , -3):
print(i,end=' ')
else:
print("else statement")
26.pattern-4
for i in range(5):
print( "$",end=' ' )
for j in range (i+1):
print(" * " , end=' ' )
for k in range(j+1):
print(i * 2,end =' ')
print()
print()
OUTPUT :
$ * 0
$ * 2 * 2 2
$ * 4 * 4 4 * 4 4 4
$ * 6 * 6 6 * 6 6 6 * 6 6 6 6
$ * 8 * 8 8 * 8 8 8 * 8 8 8 8 * 8 8 8 8
Prepared By
C VADIVELMURUGAN M.Sc.,B.Ed.,M.Phil.,DTP.,
9600519206