Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the module mymodule from the package mypackage.
Python
from mypackage import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import the package name instead of the module.
Using generic words like 'module' or 'package' instead of the actual module name.
✗ Incorrect
You import the module by its name inside the package, so
mymodule is correct.2fill in blank
mediumComplete the code to import the function greet from the module mymodule inside the package mypackage.
Python
from mypackage.mymodule import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the module name instead of the function.
Using generic words like 'function' instead of the actual function name.
✗ Incorrect
You import the function by its name, so
greet is correct.3fill in blank
hardFix the error in the import statement to correctly import the greet function from mypackage.mymodule.
Python
import mypackage.[1].greet
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a function directly using dot notation.
Using the package name twice.
✗ Incorrect
You cannot import a function directly using dot notation in an import statement like this. You must import the module first. So the correct fix is to import the module
mymodule.4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each module name in modules to its length, but only if the length is greater than 5.
Python
{module: len(module) for module in [1] if len(module) [2] 5} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for the list.
Using the wrong comparison operator.
✗ Incorrect
We iterate over the list named
modules and check if the length of each module name is greater than 5.5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each module name in modules to its uppercase version, but only if the module name starts with the letter 'a'.
Python
{ [1]: [2] for [3] in modules if [3].startswith('a') } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the comprehension.
Not calling
upper() on the module name.Using the wrong variable as key or value.
✗ Incorrect
We use
module as the key and its uppercase version as the value, iterating over module in modules.