WORK SHEET-2
SUBJECT : COMPUTER SCIENCE
LESSON : PYTHON PROGRAMMING TOPIC : CONDITIONAL STATEMENTS
NAME : CLASS:
LEARNING OBJECTIVE: To enable students to control the flow of a program by
mastering the usage of if, else, and elif statements to make decisions based on
specific conditions.
I. Give the output of the following code snippet.
CODE OUTPUT
1. num=7
if num>0:
print(‘Positive Number’)
2. a=5
b=7
if a>b:
print(a-b)
else:
print(a+b)
3. temp=27
if temp<0:
message=’Too Cold, Don’t go out’
elif temp<10:
message=’Very Cold - Try to stay in‘
elif temp<20:
message=’Wear warm cloths ‘
elif temp<35:
message=’Good Weather’
elif temp<50:
message=’Very Hot, Be Careful’
else:
message=’Too Hot, Stay in’
print(message)
Page 1 of 3
4.
Maxspeed=120
Myspeed=160
If Myspeed>Maxspeed:
print(‘You are booked’)
else:
print(‘Enjoy your Drive’)
5.
a,b=30,40
if a!=b:
if a>b:
print(a,’is greater than’,b)
else:
print(b,’is greater than’,a)
else:
print(a,’is equal to’,b)
6.
x=1
if x>3:
if x>4:
print(‘a’)
else:
print(‘b’)
elif x<2:
if (x!=0):
print(‘c’)
print(‘d’)
7.
x,y=2,4
if (x+y==10):
print(‘Good’)
else:
print(x+y)
8. x=3
if x>2 or x<5 and x==6:
print(‘OK’)
else:
print(‘No Output’)
Page 2 of 3
Correct the errors in the following code snippet.
No Given Code Corrected Code
a=input(int(‘Enter Number 1:’)
op=input(‘Enter operator :’)
1. b= input(int(‘Enter Number 2:’)
if op=+
print(a+b)
code=print(‘Season Code:’)
if code=w:
print(Winter)
2. elif code==’r’
PRINT(‘Rainy Season’)
else:
Print(‘Summer’)
a=input(‘Enter num1’)
b=int( input(‘Enter num2’))
if a=b:
print(a is equal to b)
3.
elif:
print(a is greater than b)
else:
print(b is greater than a)
a=input(‘Enter num1 :’)
b= input(‘Enter num2 :’)
c= input(‘Enter num 3 :’)
if a+b+c>1000:
4.
message=’You won’
else:
message=’Sorry’
print(message)
Is_day=true
If Isday
5. Print(‘Have a good day’)
Else
Print(‘Get a good sleep’)
Page 3 of 3