π¦ Computational Thinking & Programming-I Quiz 14 β Python Modules (Class 11 CS)
Practice 20 CBSE Class 11 Computer Science (Code 083) MCQs on Python modules β the import and from...import statements, the math module (pi, e, sqrt(), ceil(), floor(), pow(), fabs(), sin(), cos(), tan()), the random module (random(), randint(), randrange()), and the statistics module (mean(), median(), mode()).
Every function and constant below has been verified by actually running it in Python. Tap any question to reveal the answer with a clear explanation.
π¦ Modules
What is a module in Python?
- A function definition
- A conditional statement
- A mathematical equation
- A file containing Python code
Show Answer & Explanation
β Answer: (d) A file containing Python code
A module is simply a .py file containing Python code β functions, variables, classes β that can be imported and reused in other programs, e.g. math, random, and statistics.
π¦ Modules
How can you import a module named βexampleβ in Python?
- import example
- include example
- load example
- importlib example
Show Answer & Explanation
β Answer: (a) import example
import example is the correct syntax to bring a module into your program β after this, you access its contents using example.something.
π’ math Module
What is the purpose of the math module in Python?
- To perform mathematical operations
- To handle file operations
- To manipulate strings
- To control flow of execution
Show Answer & Explanation
β Answer: (a) To perform mathematical operations
The math module provides a wide range of mathematical functions and constants β square roots, trigonometry, rounding, and more.
π’ math Module
Which constant in the math module represents the mathematical constant Ο (pi)?
- math.pi
- math.e
- math.sqrt()
- math.ceil()
Show Answer & Explanation
β Answer: (a) math.pi
math.pi gives the value of Ο (approximately 3.14159…), used for circle and geometry calculations.
π’ math Module
Which function in the math module is used to calculate the square root of a number?
- math.pi
- math.e
- math.sqrt()
- math.ceil()
Show Answer & Explanation
β Answer: (c) math.sqrt()
math.sqrt() returns the square root of its argument, e.g. math.sqrt(16) gives 4.0.
π’ math Module
Which function in the math module is used to round a number UP to the nearest integer?
- math.pi
- math.e
- math.sqrt()
- math.ceil()
Show Answer & Explanation
β Answer: (d) math.ceil()
math.ceil() always rounds up β e.g. math.ceil(4.2) gives 5, even though 4.2 is much closer to 4.
π’ math Module
Which function in the math module is used to round a number DOWN to the nearest integer?
- math.pi
- math.e
- math.sqrt()
- math.floor()
Show Answer & Explanation
β Answer: (d) math.floor()
math.floor() always rounds down β e.g. math.floor(4.8) gives 4, even though 4.8 is much closer to 5.
π’ math Module
Which function in the math module is used to calculate the power of a number?
- math.pow()
- math.fabs()
- math.sin()
- math.cos()
Show Answer & Explanation
β Answer: (a) math.pow()
math.pow(x, y) calculates x raised to the power y, e.g. math.pow(2, 3) gives 8.0. (Note: it always returns a float, unlike the ** operator.)
π’ math Module
Which function in the math module is used to calculate the absolute value of a number?
- math.pow()
- math.fabs()
- math.sin()
- math.cos()
Show Answer & Explanation
β Answer: (b) math.fabs()
math.fabs() returns the absolute (always positive) value of a number as a float, e.g. math.fabs(-5) gives 5.0.
π² random Module
Which module in Python is used for generating random numbers?
- math
- random
- statistics
- numpy
Show Answer & Explanation
β Answer: (b) random
The random module provides functions to generate random numbers, make random selections, and shuffle sequences.
π² random Module
Which function in the random module generates a random floating-point number between 0 and 1?
- random()
- randint()
- randrange()
- mean()
Show Answer & Explanation
β Answer: (a) random()
random.random() returns a random float in the range [0.0, 1.0) β 0 is possible, but exactly 1.0 never is.
π² random Module
Which function in the random module generates a random integer within a specified range (inclusive of both endpoints)?
- random()
- randint()
- randrange()
- median()
Show Answer & Explanation
β Answer: (b) randint()
random.randint(a, b) returns a random whole number between a and b, with both endpoints included β e.g. randint(1, 6) can return 1 or 6.
π statistics Module
Which module in Python is used for statistical calculations?
- math
- random
- statistics
- numpy
Show Answer & Explanation
β Answer: (c) statistics
The statistics module provides built-in functions for common statistical measures like mean, median, and mode.
π statistics Module
Which function in the statistics module calculates the average (arithmetic mean) of a list of numbers?
- mean()
- median()
- mode()
- sqrt()
Show Answer & Explanation
β Answer: (a) mean()
statistics.mean() adds up all the values and divides by how many there are, giving the average.
π statistics Module
Which function in the statistics module finds the most common value(s) in a list?
- mean()
- median()
- mode()
- sqrt()
Show Answer & Explanation
β Answer: (c) mode()
statistics.mode() returns the value that appears most frequently in the data.
π¦ Modules
What is the difference between import math and from math import sqrt?
- They are functionally identical in every way
- import math brings in the whole module (use math.sqrt()); from math import sqrt brings in just that one function (use sqrt() directly)
- from math import sqrt is invalid Python syntax
- import math only works with built-in modules
Show Answer & Explanation
β Answer: (b) import math brings in the whole module (use math.sqrt()); from math import sqrt brings in just that one function (use sqrt() directly)
With import math, you must prefix every function with math., e.g. math.sqrt(25). With from math import sqrt, you import just that specific function and can call it directly as sqrt(25), without the module prefix.
π’ math Module
What is the approximate value of the math module’s constant e?
- 3.14159…
- 2.71828…
- 1.41421…
- 1.61803…
Show Answer & Explanation
β Answer: (b) 2.71828…
math.e represents Euler’s number, approximately 2.71828 β the base of natural logarithms, distinct from math.pi (3.14159…).
π’ math Module
What unit do math.sin(), math.cos(), and math.tan() expect their input angle to be in?
- Degrees
- Radians
- Gradians
- Percent
Show Answer & Explanation
β Answer: (b) Radians
Python’s trigonometric functions expect angles in radians, not degrees β so math.sin(90) does NOT give you sin of 90 degrees. To convert, use math.radians(degrees) first, or use math.sin(math.pi/2) for a 90Β° angle.
π² random Module
What does random.randrange(1, 10) generate?
- A random float between 1 and 10
- A random integer from 1 up to (but NOT including) 10
- A random integer from 1 to 10, inclusive of both
- Always returns exactly 10
Show Answer & Explanation
β Answer: (b) A random integer from 1 up to (but NOT including) 10
randrange() behaves like range() β the stop value is excluded. So randrange(1, 10) can return any integer from 1 to 9, but never 10 itself (unlike randint(1, 10), which would include 10).
π statistics Module
What does statistics.median() calculate for a list of numbers?
- The sum of all values
- The value that appears most often
- The middle value when the data is sorted
- The largest value in the list
Show Answer & Explanation
β Answer: (c) The middle value when the data is sorted
median() sorts the data and returns the middle value β or the average of the two middle values if there’s an even number of items.
