0
0
Pythonprogramming~10 mins

Why modules are needed 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 math module.

Python
import [1]
Drag options to blanks, or click blank then click option'
Amath
Bsys
Crandom
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Using a module name unrelated to math.
Forgetting to import the module before using it.
2fill in blank
medium

Complete 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'
Apow
Bsin
Clog
Dsqrt
Attempts:
3 left
💡 Hint
Common Mistakes
Using pow which raises a number to a power.
Using unrelated functions like log or sin.
3fill in blank
hard

Fix 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'
Arandint
Brandomint
Crand
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Using randomint which does not exist.
Using rand or random which are incorrect here.
4fill in blank
hard

Fill 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'
Apow
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality '==' instead of greater than '>'.
Using incorrect function names for power.
5fill in blank
hard

Fill 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'
Anum
Bsqrt
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inside the comprehension.
Using a wrong function name instead of sqrt.