Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if 5 is in the set.
Python
numbers = {1, 3, 5, 7}
if 5 [1] numbers:
print("Found 5") Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 'not in' instead of 'in'.
Using 'contains' which is not a Python keyword.
Using 'inside' which is not valid syntax.
โ Incorrect
The keyword in checks if an item is in a set.
2fill in blank
mediumComplete the code to check if 'apple' is NOT in the set.
Python
fruits = {'banana', 'orange', 'grape'}
if 'apple' [1] fruits:
print("Apple is missing") Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 'in' instead of 'not in'.
Using 'contains' or 'has' which are not Python keywords.
โ Incorrect
The keyword not in checks if an item is NOT in a set.
3fill in blank
hardFix the error in the code to correctly test membership.
Python
colors = {'red', 'blue', 'green'}
if 'yellow' [1] colors:
print("Yellow found")
else:
print("Yellow not found") Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using 'inside' or 'contains' which cause syntax errors.
Using 'not in' when checking for presence.
โ Incorrect
Use in to check if 'yellow' is in the set.
4fill in blank
hardFill both blanks to create a set of squares for numbers greater than 3.
Python
squares = {x[1]2 for x in range(1, 7) if x [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '+' instead of '**' for squaring.
Using '<' instead of '>' for filtering.
โ Incorrect
Use ** to square numbers and > to filter numbers greater than 3.
5fill in blank
hardFill all three blanks to create a set of uppercase words longer than 4 letters.
Python
result = {word[1] for word in words if len(word) [2] 4 and word.isalpha() [3] True} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '+' or other operators instead of '.upper()'.
Using '<' instead of '>' for length check.
Using '=' instead of '==' for comparison.
โ Incorrect
Use .upper() to convert words to uppercase, > to check length greater than 4, and == to check if isalpha() returns True.