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 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')

Exercise 2

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!')

References

Code copied to clipboard successfully 👍