Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the length of the string.
Python
word = "hello" print(len([1]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using quotes around the variable name like "word" which is a string literal, not the variable.
Using
len(word) inside len() causing an error.โ Incorrect
The len() function needs the variable word to get the string length.
2fill in blank
mediumComplete the code to check if the letter 'a' is in the string.
Python
text = "apple" if [1] in text: print("Found a")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the variable name without quotes, which causes a NameError.
Using quotes around the variable name instead of the letter.
โ Incorrect
To check membership, the letter must be a string literal like "a".
3fill in blank
hardFix the error in the code to check if 'x' is not in the string.
Python
my_str = "example" if 'x' [1] my_str: print("No x found")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using only
not without in.Using
!= which compares equality, not membership.โ Incorrect
The correct syntax to check if a character is not in a string is not in.
4fill in blank
hardFill both blanks to create a dictionary of words with length greater than 3.
Python
words = ["cat", "lion", "dog", "tiger"] lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the word itself instead of its length.
Using less than operator which filters wrong words.
โ Incorrect
The dictionary maps each word to its length, but only if the length is greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values longer than 4.
Python
words = ["apple", "pear", "banana", "kiwi"] result = [1]: [2] for w in words if len(w) [3] 4}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using length as value instead of the word.
Using less than operator which filters wrong words.
โ Incorrect
The dictionary uses uppercase words as keys and original words as values, filtering words longer than 4.