Professional Documents
Culture Documents
Ans: To check if a is greater than 2 the if statement is used. Here comparison operator (>) shall be
used to compare the value of variable a with 2. The ":" in the if statement is used to separate the
header of the compound statement from the body. So, the correct way of using the if statement, in
this case, is
if a > 2:
Q2. Which keyword do we use to add alternative conditions for the if statement?
else if
elseif
elif
if test expression:
Body of if
Body of elif
else:
Body of else
Here elif is used to check for a different test expressions as an alternative to write mulitple if
statements (all of the mentioned)
if 4 + 3 == 9:
else:
print("Hello")
Ans: The addition of 4 and 3 is 7 and is not equal to 9 hence else statement will be executed. The last
print statement is outside if statement so it will be by default executed.
Hello
a = b = TRUE
if (a == b):
print("Hello")
else:
print("Well done")
Ans: Here "TRUE" is not defined so can not be compared with a and b hence Python will prompt
NameError: name 'TRUE' is not defined.