0
0
Pythonprogramming~10 mins

Why standard library modules are used in Python - Test Your Understanding

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

Complete the code to import the module that helps with math operations.

Python
import [1]
Drag options to blanks, or click blank then click option'
Asys
Brandom
Cos
Dmath
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong module that doesn't provide math functions.
Forgetting to import any module and trying to use math functions directly.
2fill in blank
medium

Complete the code to use the randint function from the random module.

Python
from random import [1]
number = randint(1, 10)
Drag options to blanks, or click blank then click option'
Arandint
Bchoice
Cshuffle
Dseed
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a function that doesn't generate integers.
Using the module name instead of the function name in the import.
3fill in blank
hard

Fix the error in the code by completing the import statement correctly.

Python
import [1]
print(os.name)
Drag options to blanks, or click blank then click option'
Amath
Brandom
Cos
Dsys
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a module that does not have the name attribute.
Forgetting to import the module before using it.
4fill in blank
hard

Fill both blanks to create a list of squares using the range function and a standard library feature.

Python
squares = [x[1]2 for x in [2](1, 6)]
Drag options to blanks, or click blank then click option'
A**
B*
Crange
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of exponentiation for squares.
Using a wrong function instead of range.
5fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Python
lengths = {word: {BLANK_2}} for [2] in words if len({{BLANK_3}}) > 3
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting the dictionary comprehension with a curly brace.
Using the wrong variable name in the comprehension.
Mixing up keys and values.