
CBSE Python Question Bank on if else
- Categories Python, Python if-else, Python
CBSE Python Question Bank – ( 2 Marks Problems on if else):
1)What is the output of following code ?
if(4+5==10):
print("True")
else:
print("False")
print("True")
Ans. False
True
2)What is the output of the following code
if a=1 and a =4
if(a==0):
print("zero")
if(a==1):
print("one")
else :
print("a > 1")Ans.
if a =1 >>> one if a=4 >>> a > 1
3)Under what conditions will this code fragment print ”water”
if temp < 32:
print("ice:")
elif temp < 212:
print("water")
else:
print("steam")
Ans. if temp greater than 32 and less than 212 it will print water
4)What is the output produced by the following code?
x=1
if x>3 :
if x>4:
print("a", end='')
else:
print('b',end=' ')
elif x < 2:
if(x != 0):
print("c", end=' ')
print("d")
Ans. c d
5)What is the error in following code ? Correct the code?
weather='raining'
if weather = "sunny":
print("wear sunblock")
elif weather="snow":
print("going skiing")
else:
print(weather)Ans.
weather='raining'
if weather == "sunny":
print("wear sunblock")
elif weather=="snow":
print("going skiing")
else:
print(weather)
>>>raining 6)What is the error in following code ? Correct the code?
n=2
if n == 0
print("zero")
elif : n==1
print("one")
elif n==2:
print("two")
else n==3:
print("three")
Ans.
n=2
if n == 0:
print("zero")
elif n==1:
print("one")
elif n==2:
print("two")
else:
print("three")7)Which are two types of else clauses in Python, define them?
Ans.
The two types of python else clauses are:
else in an if statement- the else clause of an if statement is executed when the condition of the if statement results into false
else in a loop statement- The else clause of a loop is executed when the loop is terminating normally. i.e. when its test- condition has gone false for a while loop or when the for loop has executed for the last value in sequence
8)Write a program to check if the number is buzz nos or not (BUZZ nos are numbers which are divisible by 7 or end with 7)
Ans.
n=int(input("Enter a number:"))
if(n % 7 == 0 or n % 10 == 7):
print (("It’s a BUZZ no"))
else:
print ("Not a BUZZ no") 9)Write a program to check if the character is a vowel or not?
Ans.
ch=input("Enter a character:")
if ch in "aeiouAEIOU":
print("It’s a vowel")
else:
print ("Not a vowel") 10)Predict the output of the program.
a = 10 if 5 < a < 15 : print (a / 2) else: print (a / 5)
Ans . >>>5.0
You may also like

Learn Python for & while
19 June, 2021

Learn Python if elif else
15 June, 2021

Python List
15 June, 2021
