Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the custom module named mymodule.
Python
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a module that is not in the same folder or Python path.
Using the wrong module name.
✗ Incorrect
To use a custom module named
mymodule, you import it with import mymodule.2fill in blank
mediumComplete the code to call the function greet from the mymodule.
Python
mymodule.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function name that does not exist in the module.
Forgetting the parentheses to call the function.
✗ Incorrect
To call the function
greet from mymodule, use mymodule.greet().3fill in blank
hardFix the error in the import statement to correctly import the greet function from mymodule.
Python
from mymodule [1] greet
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keywords like
importing or include.Misspelling
import.✗ Incorrect
The correct syntax to import a function is
from module import function.4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each word to its length from the list words, but only for words longer than 3 characters.
Python
{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 wrong comparison operator like
<.Using the word itself instead of its length.
✗ Incorrect
The dictionary comprehension uses
len(word) to get the length and filters words with length greater than 3 using >.5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths, but only for words with length greater than 4.
Python
{ [1]: [2] for word in words if len(word) [3] 4 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
word.lower() instead of uppercase.Using wrong comparison operators like
< or ==.✗ Incorrect
The comprehension maps
word.upper() to len(word) for words longer than 4 using >.