Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the math module.
Python
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a module name unrelated to math.
Forgetting to import the module before using it.
✗ Incorrect
The math module provides mathematical functions. We import it using import math.
2fill in blank
mediumComplete the code to use the square root function from the math module.
Python
result = math.[1](16)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
pow which raises a number to a power.Using unrelated functions like
log or sin.✗ Incorrect
The sqrt function calculates the square root of a number.
3fill in blank
hardFix the error in the code to correctly use the random module to get a random number.
Python
import random number = random.[1](1, 10)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
randomint which does not exist.Using
rand or random which are incorrect here.✗ Incorrect
The correct function to get a random integer between two numbers is randint.
4fill in blank
hardFill both blanks to create a list of squares using a module function.
Python
import math squares = [math.[1](x, 2) for x in range(1, 6) if x [2] 0]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality '==' instead of greater than '>'.
Using incorrect function names for power.
✗ Incorrect
We use pow(x, 2) to square numbers and filter numbers greater than 0.
5fill in blank
hardFill all three blanks to create a dictionary of numbers and their square roots using the math module.
Python
import math roots = { [1]: math.[2]([3]) for [1] in range(1, 5) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inside the comprehension.
Using a wrong function name instead of
sqrt.✗ Incorrect
We use num as the variable name and sqrt function from math to get square roots.