Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the sqrt function from the math module.
Python
from math import [1] result = sqrt(16) print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole math module instead of just sqrt.
Using a function name that does not exist in math.
✗ Incorrect
We use
from math import sqrt to import only the sqrt function from the math module.2fill in blank
mediumComplete the code to import the choice function from the random module.
Python
from random import [1] items = ['apple', 'banana', 'cherry'] print(choice(items))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a function that shuffles the list instead of picking one item.
Using a function that generates random numbers instead of selecting items.
✗ Incorrect
The
choice function picks a random item from a list. We import it specifically from the random module.3fill in blank
hardFix the error in the code by importing the correct item from the datetime module.
Python
from datetime import [1] now = datetime.now() print(now)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'date' or 'time' which do not have the now() method.
Not importing the class named 'datetime'.
✗ Incorrect
To use
datetime.now(), we must import the datetime class from the datetime module.4fill in blank
hardFill both blanks to import sin and cos from the math module.
Python
from math import [1], [2] angle = 0.5 print(sin(angle)) print(cos(angle))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'tan' or 'log' instead of 'cos'.
Importing only one function instead of both.
✗ Incorrect
We import both
sin and cos functions from math to use them directly.5fill in blank
hardFill all three blanks to import join, split, and exists from their respective modules.
Python
from os.path import [1] from os.path import [2] from os.path import [3] print(join('folder', 'file.txt')) print(split('folder/file.txt')) print(exists('folder/file.txt'))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing os.path.split with the string method split.
Importing path instead of join, split, or exists.
✗ Incorrect
We import
join, split, and exists from os.path.