0
0
Pythonprogramming~10 mins

If statement execution flow in Python - Interactive Code Practice

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

Complete the code to print 'Yes' if the number is greater than 10.

Python
number = 15
if number [1] 10:
    print("Yes")
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check the wrong condition.
Using '==' checks equality, not greater than.
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.
Using '**' is for powers, not division.
3fill in blank
hard

Fix the error in the if statement to correctly check if x is not equal to 5.

Python
x = 7
if x [1] 5:
    print("Not five")
Drag options to blanks, or click blank then click option'
A==
B!=
C=
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '!=' causes a syntax error.
Using '<>' is not supported in Python 3.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their lengths, but only for words longer than 3 letters.

Python
words = ["apple", "cat", "banana", "dog"]
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' includes words with length 3 or less.
Using 'word' instead of 'len(word)' gives the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if the value is positive.

Python
data = {"a": 1, "b": -2, "c": 3}
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()' keeps keys lowercase.
Using '<' instead of '>' filters wrong values.