Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the string 'Hello, World!'.
Python
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the text.
Using quotes inconsistently or missing them.
✗ Incorrect
Strings in Python must be enclosed in quotes to be recognized as text.
2fill in blank
mediumComplete the code to get the length of the string stored in variable text.
Python
length = [1](text) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like count or size for length.
Trying to access length as an attribute instead of a function.
✗ Incorrect
The built-in function len() returns the number of characters in a string.
3fill in blank
hardFix the error in the code to convert the string to uppercase.
Python
result = text.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using JavaScript style method names like toUpperCase.
Capitalizing method names incorrectly.
✗ Incorrect
The correct method to convert a string to uppercase in Python is upper().
4fill in blank
hardFill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 characters.
Python
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 as the value instead of its length.
Using the wrong comparison operator in the condition.
✗ Incorrect
We use len(word) to get the length and filter words with length greater than 3 using >.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase words as keys, their original form as values, only for words starting with 'a'.
Python
result = {{ [1]: [2] for word in words if word.[3]('a')} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower() instead of upper() for keys.
Using the wrong method name for checking the start of a string.
✗ Incorrect
Use word.upper() for keys, word for values, and startswith('a') to filter words starting with 'a'.