04.04 Using Standard Modules - Quiz¶
Check your understanding
-
Which statement correctly imports the math module?
include mathimport math{ data-correct }use mathfrom python import math
-
What does
math.sqrt(25)return?- 25
- 5.0 { data-correct }
- 625
- An error
-
Which function generates a random integer between 1 and 10 (inclusive)?
random.random(1, 10)random.randint(1, 10){ data-correct }random.range(1, 10)random.integer(1, 10)
-
What is the value of
math.ceil(4.2)?- 4
- 5 { data-correct }
- 4.2
- 4.0
-
Which function would you use to randomly select one item from a list?
random.select()random.pick()random.choice(){ data-correct }random.get()
-
What does
math.pirepresent?- The value 3.14159… { data-correct }
- A function to calculate pi
- The variable name for pi
- An error
-
What does
random.seed(42)do?- Generates the number 42
- Sets the random number generator to produce reproducible sequences { data-correct }
- Creates 42 random numbers
- Limits random numbers to 42
-
Which function calculates the square of a number using the math module?
math.square(x)math.pow(x, 2){ data-correct }math.sqrt(x)math.exp(x)
-
What is a “pure function”?
- A function that only uses built-in Python features
- A function that always returns the same output for the same input and has no side effects { data-correct }
- A function that doesn’t use any modules
- A function written in pure Python code
-
What does
random.uniform(5.0, 10.0)return?- Always 7.5
- A random integer between 5 and 10
- A random float between 5.0 and 10.0 { data-correct }
- A list of numbers from 5 to 10
-
Which import statement is generally preferred for clarity?
from math import *import math{ data-correct }import math as mfrom math import everything
-
What does
math.radians(90)convert?- 90 radians to degrees
- 90 degrees to radians { data-correct }
- 90 to square root
- 90 to logarithm