0
0
Pythonprogramming~10 mins

Why conditional statements are needed in Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message only if the number is positive.

Python
number = 5
if number [1] 0:
    print("Number is positive")
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check if the number is negative, which is not what we want.
2fill in blank
medium

Complete the code to print 'Even' if the number is divisible by 2.

Python
number = 8
if number [1] 2 == 0:
    print("Even")
Drag options to blanks, or click blank then click option'
A%
B//
C**
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' gives the quotient, not the remainder.
3fill in blank
hard

Fix the error in the code to check if a number is not zero.

Python
number = 0
if number [1] 0:
    print("Number is not zero")
Drag options to blanks, or click blank then click option'
A>=
B==
C!=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' checks equality, which is the opposite of what we want.
4fill in blank
hard

Fill both blanks to create a dictionary of squares for numbers greater than 3.

Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3}
Drag options to blanks, or click blank then click option'
A**
B%
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '%' instead of '**' will not square the number.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and values greater than zero.

Python
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' will not change key case.