0
0
Pythonprogramming~10 mins

Comparison operators 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 check if 5 is greater than 3.

Python
result = 5 [1] 3
print(result)
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will give False.
Using '==' checks equality, not greater than.
2fill in blank
medium

Complete the code to check if 10 is equal to 10.

Python
is_equal = 10 [1] 10
print(is_equal)
Drag options to blanks, or click blank then click option'
A==
B>
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' causes an error.
Using '!=' checks for inequality, not equality.
3fill in blank
hard

Fix the error in the code to check if 7 is less than or equal to 5.

Python
check = 7 [1] 5
print(check)
Drag options to blanks, or click blank then click option'
A<
B<=
C=>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=>' causes a syntax error.
Using '<' only checks less than, not equal.
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
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 'word' instead of 'len(word)' gives the word itself, not length.
Using '<' filters words shorter than 3 letters.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys, values as word lengths, only for words with length greater than 4.

Python
result = { [1]: [2] for word in words if len(word) [3] 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of word.upper() changes case incorrectly.
Using '<' filters shorter words, not longer.