Professional Documents
Culture Documents
Notes 02
Notes 02
x = input()
print (x)
CONDITIONAL STATEMENTS
- The IF Statement
if x > y:
print (x, 'is greater than', y)
x
z = 5
if z <= x :
print (z, 'is less than or eqaul to',
x)
if z == x :
print (z, 'is eqaul to', x)
if z != y :
print (z, 'is not eqaul to', y)
if z < y > x:
print (y, 'is greater than', z, 'and
greater than', x)
a = 3
- The IF ELSE
x = 5
y = 8
if x > y:
print (x, 'is greater than', y)
else:
print (x, 'is not greater than', y)
if x > 5:
print (x, 'is greater than', y)
elif 5 > 2:
print ('5 is greater than 2')
x = 5
y = 10
z = 22
if x > 5:
print (x, 'is greater than', y)
elif x < z:
print (x, 'is less than', z)
elif 5 > 2:
print ('5 is less than 2')
else:
print('if and elif(s) never ran')
EXERCISES
1. Write program that will accept an age (of a voter), it will
check if the voter can vote or not. If the voter is 18 years
or over, the program will display "You can vote", if the
voter is less than 18, it will display, "Sorry, you are not
eligible to vote".
Answer
x = int (input ('Enter your age: '))
if x < 18:
print ('You are not eligible to vote')
else:
print ('You are eligible to vote')