Exercises on Python If, If-Else, Elif

The following exercises cover scenarios on console operations in Python, that is to read input from user, or print some values to standard output for user.

Exercise 1 – If statement

If value in a is greater than that of b, we print a message ‘Hello World’ to the output.

Insert the keyword used for Python If statement in the following code.

a = 10
b = 20
 a > b:
    print('Hello World')
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.

Exercise 2 – If else

If value in a is greater than that of b, we print a message ‘Hello World’ to the output. Else, we print the message, ‘Hello user!’

Insert the keyword used for Python If Else conditional statement in the following code.

a = 10
b = 20
 a > b:
    print('Hello World')
:
    print('Hello user!')
Submit Answer
↻ Reset
Show Answer
Fill the fields with missing code.

References