The Python math Module Class 11: Functions, Constants and the Four Import Forms
Updated 17 October 2026 · Fact-checked
A module is a file of ready-made code. import math gives access to functions as math.sqrt(); from math import sqrt lets you write sqrt() directly; import math as m shortens the prefix; from math import * imports everything. math.ceil() rounds up and math.floor() rounds down (so ceil(-2.5) is -2 and floor(-2.5) is -3); sin and cos take angles in radians.
Notice that only import math needs the math. prefix before sqrt; using bare sqrt(49) after plain import math gives NameError.
Illustration drawn for QuestionBuddy.
Understand The math Module: Functions, Constants and Import Forms
Import forms.
import math
print(math.sqrt(49)) # 7.0
from math import sqrt, pi
print(sqrt(16)) # 4.0
import math as m
print(m.fabs(-3)) # 3.0
from math import *After import math, writing sqrt(49) without the prefix gives NameError: name 'sqrt' is not defined.
Constants. math.pi = 3.141592653589793; math.e is Euler's number.
Functions.
math.sqrt(x): square root, always float: sqrt(49) = 7.0.math.pow(x, y): x to the power y, always float: pow(2, 3) = 8.0 (the ** operator gives 8 for ints).math.fabs(x): absolute value as float: fabs(-3) = 3.0 (the built-in abs(-3) gives int 3).math.ceil(x): smallest integer not less than x: ceil(4.2) = 5, ceil(-2.5) = -2.math.floor(x): largest integer not greater than x: floor(4.8) = 4, floor(-2.5) = -3.math.sin(x),math.cos(x),math.tan(x): x in radians. sin(0) = 0.0, cos(0) = 1.0, sin(math.pi / 2) = 1.0, cos(math.pi) = -1.0.
Programs.
import math
r = 7
area = math.pi * r * r
print(round(area, 2)) # 153.94
print(math.sqrt(3**2 + 4**2)) # 5.0round(153.938..., 2) gives 153.94. The hypotenuse of a 3-4 right triangle is 5.0.
Built-in versus module functions. abs(), round(), max(), min(), pow() (built-in with different behaviour), len() and print() need no import; sqrt, ceil, floor, sin, cos are in math.
Degrees to radians. radians = degrees x math.pi / 180. So 90 degrees is math.pi / 2.
The math Module: Functions, Constants and Import Forms: key facts
- Import forms
import math use math.sqrt() from math import sqrt use sqrt() import math as m use m.sqrt() from math import star everything without prefix - Pick one style.
- Rounding
- ceil rounds up
- floor rounds down
- ceil(-2.5) = -2
- floor(-2.5) = -3
- Negatives need care.
- Return types
- sqrt returns float
- pow returns float
- fabs returns float
- ceil and floor return int
- sqrt(49) is 7.0.
- Trigonometry
- Angles in radians
- radians = degrees x pi / 180
- sin(pi/2) = 1.0
- cos(0) = 1.0
- math.pi = 3.141592653589793.
How to answer The math Module: Functions, Constants and Import Forms questions
Output questions ask for exact return values and types.
- 1Note how the module was imported (prefix or no prefix).
- 2Evaluate the argument first.
- 3Apply the function; remember whether it returns an int or a float.
- 4For ceil and floor with negatives, think of the number line.
- 5Write the output exactly, for example 7.0, not 7.
The math Module: Functions, Constants and Import Forms in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Number of boxes
Suppose 47 pens must be packed into boxes that hold 10 each.
How many boxes are needed, using math?
Try it first, then show the solutionSolution
- 47 / 10 = 4.7.
- math.ceil(4.7) = 5.
Answer: 5 boxes.
Memory hook: Round up when a partial box still needs a box.
Tricks to remember The math Module: Functions, Constants and Import Forms
Short memory aids. Say each one aloud once, then use it on a question the same day.
Ceil climbs, floor falls
ceil goes up the number line; floor goes down, even for negatives.
Use it when: ceil and floor.
Prefix or not
import math needs math.; from math import sqrt does not.
Use it when: Import forms.
The math Module: Functions, Constants and Import Forms: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Import form · 1 mark · MCQBoard level
After the statement import math, the correct call for a square root is:
(a) sqrt(25)
(b) math.sqrt(25)
(c) math(sqrt, 25)
(d) import sqrt(25)
Try it first, then show the solutionSolution
- The module name is the prefix.
Answer: (b) math.sqrt(25)
Example 2: Outputs · 5 marks · Short answerBoard level
Give the output: (i) math.sqrt(49); (ii) math.pow(2, 3); (iii) math.fabs(-3); (iv) math.ceil(-2.5); (v) math.floor(-2.5). (5 marks)
Try it first, then show the solutionSolution
- (i) 7.0.
- (ii) 8.0.
- (iii) 3.0.
- (iv) -2 (the smallest integer not less than -2.5).
- (v) -3 (the largest integer not greater than -2.5).
Answer: 7.0, 8.0, 3.0, -2, -3.
Example 3: Area of a circle · 4 marks · Short answerHarder board level
Write a program to input the radius of a circle and print its area and circumference correct to 2 decimal places using the math module. State the output for radius 7. (4 marks)
Try it first, then show the solutionSolution
- import math; r = float(input("Radius: ")); print(round(math.pi * r * r, 2)); print(round(2 * math.pi * r, 2)).
- For r = 7: area = 49 x 3.14159... = 153.94 (rounded to 2 decimals).
- Circumference = 2 x 3.14159... x 7 = 43.98.
Answer: Area 153.94; circumference 43.98.
Example 4: Import errors · 4 marks · Short answerHarder board level
Predict the result of each: (i) import math then print(sqrt(16)); (ii) from math import sqrt then print(sqrt(16)); (iii) import math as m then print(m.floor(4.8), m.ceil(4.2)). (4 marks)
Try it first, then show the solutionSolution
- (i) NameError: name 'sqrt' is not defined, since only math was imported.
- (ii) 4.0.
- (iii) floor(4.8) is 4 and ceil(4.2) is 5: output 4 5.
Answer: (i) NameError (ii) 4.0 (iii) 4 5
Example 5: Radians · 5 marks · Short answerHOTS / competency
Write the output of the program and explain why sin(90) in Python does not give 1:
import math
print(math.sin(math.pi / 2))
print(math.cos(math.pi))
print(math.sin(math.radians(90)))(5 marks)
Try it first, then show the solutionSolution
- math.sin takes radians: pi / 2 radians is 90 degrees, so sin gives 1.0.
- cos(pi) is -1.0.
- math.radians(90) converts degrees to pi / 2, so the third line also gives 1.0.
- sin(90) treats 90 as radians (about 14.3 full turns), which is not 1.
- Output lines: 1.0, -1.0, 1.0.
Answer: 1.0, -1.0, 1.0; angles must be in radians.
Where students lose marks in The math Module: Functions, Constants and Import Forms
The slips examiners see most often, and what to write instead.
Mistake: Forgetting the prefix
Using sqrt() after import math.
Wrong working
sqrt(25)
Right working
math.sqrt(25)
Do this: Use the module name unless from-import was used.
Usually costs: 1 mark
Mistake: Writing 7 instead of 7.0
Ignoring the float result.
Wrong working
Output: 7
Right working
Output: 7.0
Do this: sqrt and pow return floats.
Usually costs: 1/2 mark
Mistake: ceil and floor mixed for negatives
Rounding toward zero.
Wrong working
floor(-2.5) = -2
Right working
floor(-2.5) = -3; ceil(-2.5) = -2
Do this: Check the number line.
Usually costs: 1 mark
Exam tips
- Write the import statement at the top of every program.
- Give outputs with their exact decimal form.
- Sketch the number line for ceil and floor with negatives.
- Convert degrees to radians before using sin, cos, tan.
Practice questions on The math Module: Functions, Constants and Import Forms
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
What is the output of print(math.floor(-3.2)) after import math?
(a) -3
(b) -4
(c) -3.0
(d) 3Hint
Down the number line.
Answer
(b) -4
Q2 · 3 marks · Short answerHarder board level
Give the output: print(math.pow(3, 2), math.ceil(4.2), math.floor(4.8)) after import math. (3 marks)
Hint
pow returns a float.
Answer
9.0 5 4
Q3 · 3 marks · Short answerHarder board level
Write a program using the math module to read two sides of a right triangle and print the hypotenuse. Give the output for 6 and 8. (3 marks)
Hint
sqrt of sum of squares.
Answer
import math; a = float(input()); b = float(input()); print(math.sqrt(a * a + b * b)). For 6 and 8: 10.0.
Q4 · 1 mark · Assertion-reasonHarder board level
Assertion (A): After from math import sqrt, the call math.sqrt(9) works.
Reason (R): from-import does not bring the module name math into the program.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
Name not imported.
Answer
(d) A is false, but R is true.
Q5 · 4 marks · Short answerHOTS / competency
A shop packs 47 pens into boxes of 10. Write the code to find the number of boxes using math and also without the math module, and explain which is simpler. (4 marks)
Hint
Ceiling of 4.7.
Answer
With math: import math; print(math.ceil(47 / 10)) gives 5. Without math: print(-(-47 // 10)) gives 5, or print(47 // 10 + (47 % 10 > 0)) gives 5. The math.ceil version is clearest.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Return type of math.sqrt?Show answer
float.
2.Value of math.ceil(-2.5)?Show answer
-2.
3.Value of math.floor(-2.5)?Show answer
-3.
4.Unit of angles in math.sin?Show answer
Radians.
5.Which import avoids the prefix?Show answer
from math import sqrt.
The math Module: Functions, Constants and Import Forms: frequently asked questions
What is a module?
A file of functions and constants that can be imported into a program.
Is abs() in math?
No, abs() is built in; math.fabs() is in math and returns a float.
Why does sin(90) not give 1?
Because 90 is taken as radians, not degrees.