0
0
Pythonprogramming~10 mins

Package structure and usage in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Amypackage
Bpackage
Cmodule
Dmymodule
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.
2fill in blank
medium

Complete 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'
Agreet
Bmypackage
Cmymodule
Dfunction
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.
3fill in blank
hard

Fix 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'
Amymodule
Bmypackage
Cgreet
Dfunction
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a function directly using dot notation.
Using the package name twice.
4fill in blank
hard

Fill 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'
Amodules
B>
C<
Dmodule_list
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for the list.
Using the wrong comparison operator.
5fill in blank
hard

Fill 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'
Amodule
Bmodule.upper()
Dmod
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.