Page 115 - PortGPT_V2.1_C7_Flipbook
P. 115
2. Fill in the blanks using the words from the help box.
True, top-down, elif, False
a. If a conditional expression return , statements inside the if block are
executed.
b. The else part is executed only when the condition specified with if returns .
c. The if…elif…else ladder follows a approach.
d. There can be multiple blocks with the if block.
3. Short answer type questions.
a. What will be the output of the following code, if x = -10:
if (x > 10):
print("x is greater than 10")
elif (x < 10):
print("x is less than or equal to 10")
else:
print("No conditions are true")
___________________________________________________________________________
___________________________________________________________________________
b. Abhi has written the following code to check whether the number is divisible by 4 and 5. But
he is getting an error. What could be the possible reason?
number = int(input("Enter a number: "))
if (number % 4 = 0 and number % 5 = 0):
print(number, "is divisible by both 4 and 5.")
elif (number % 4 = 0):
print(number, "is divisible by 4 but not by 5.")
elif (number % 5 = 0):
print(number, "is divisible by 5 but not by 4.")
else:
print(number, "is neither divisible by 4 nor by 5.")
___________________________________________________________________________
___________________________________________________________________________
Conditional Statements in Python 113

