Computational Thinking and Programming-I Quiz 14

πŸ“¦ 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πŸ”’ math Module🎲 random ModuleπŸ“Š statistics Module
Q1
πŸ“¦ Modules

What is a module in Python?

  1. A function definition
  2. A conditional statement
  3. A mathematical equation
  4. 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.

Q2
πŸ“¦ Modules

How can you import a module named β€œexample” in Python?

  1. import example
  2. include example
  3. load example
  4. 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.

Q3
πŸ”’ math Module

What is the purpose of the math module in Python?

  1. To perform mathematical operations
  2. To handle file operations
  3. To manipulate strings
  4. 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.

Q4
πŸ”’ math Module

Which constant in the math module represents the mathematical constant Ο€ (pi)?

  1. math.pi
  2. math.e
  3. math.sqrt()
  4. math.ceil()
Show Answer & Explanation

βœ… Answer: (a) math.pi

math.pi gives the value of Ο€ (approximately 3.14159…), used for circle and geometry calculations.

Q5
πŸ”’ math Module

Which function in the math module is used to calculate the square root of a number?

  1. math.pi
  2. math.e
  3. math.sqrt()
  4. 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.

Q6
πŸ”’ math Module

Which function in the math module is used to round a number UP to the nearest integer?

  1. math.pi
  2. math.e
  3. math.sqrt()
  4. 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.

Q7
πŸ”’ math Module

Which function in the math module is used to round a number DOWN to the nearest integer?

  1. math.pi
  2. math.e
  3. math.sqrt()
  4. 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.

Q8
πŸ”’ math Module

Which function in the math module is used to calculate the power of a number?

  1. math.pow()
  2. math.fabs()
  3. math.sin()
  4. 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.)

Q9
πŸ”’ math Module

Which function in the math module is used to calculate the absolute value of a number?

  1. math.pow()
  2. math.fabs()
  3. math.sin()
  4. 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.

Q10
🎲 random Module

Which module in Python is used for generating random numbers?

  1. math
  2. random
  3. statistics
  4. numpy
Show Answer & Explanation

βœ… Answer: (b) random

The random module provides functions to generate random numbers, make random selections, and shuffle sequences.

Q11
🎲 random Module

Which function in the random module generates a random floating-point number between 0 and 1?

  1. random()
  2. randint()
  3. randrange()
  4. 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.

Q12
🎲 random Module

Which function in the random module generates a random integer within a specified range (inclusive of both endpoints)?

  1. random()
  2. randint()
  3. randrange()
  4. 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.

Q13
πŸ“Š statistics Module

Which module in Python is used for statistical calculations?

  1. math
  2. random
  3. statistics
  4. numpy
Show Answer & Explanation

βœ… Answer: (c) statistics

The statistics module provides built-in functions for common statistical measures like mean, median, and mode.

Q14
πŸ“Š statistics Module

Which function in the statistics module calculates the average (arithmetic mean) of a list of numbers?

  1. mean()
  2. median()
  3. mode()
  4. sqrt()
Show Answer & Explanation

βœ… Answer: (a) mean()

statistics.mean() adds up all the values and divides by how many there are, giving the average.

Q15
πŸ“Š statistics Module

Which function in the statistics module finds the most common value(s) in a list?

  1. mean()
  2. median()
  3. mode()
  4. sqrt()
Show Answer & Explanation

βœ… Answer: (c) mode()

statistics.mode() returns the value that appears most frequently in the data.

Q16
πŸ“¦ Modules

What is the difference between import math and from math import sqrt?

  1. They are functionally identical in every way
  2. import math brings in the whole module (use math.sqrt()); from math import sqrt brings in just that one function (use sqrt() directly)
  3. from math import sqrt is invalid Python syntax
  4. 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.

Q17
πŸ”’ math Module

What is the approximate value of the math module’s constant e?

  1. 3.14159…
  2. 2.71828…
  3. 1.41421…
  4. 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…).

Q18
πŸ”’ math Module

What unit do math.sin(), math.cos(), and math.tan() expect their input angle to be in?

  1. Degrees
  2. Radians
  3. Gradians
  4. 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.

Q19
🎲 random Module

What does random.randrange(1, 10) generate?

  1. A random float between 1 and 10
  2. A random integer from 1 up to (but NOT including) 10
  3. A random integer from 1 to 10, inclusive of both
  4. 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).

Q20
πŸ“Š statistics Module

What does statistics.median() calculate for a list of numbers?

  1. The sum of all values
  2. The value that appears most often
  3. The middle value when the data is sorted
  4. 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.

Jitendra Singh
βœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me β†’