Python Practice › Basic Programs › Program 38
Square root of a number
Write a Python program to find the square root of a number using the math library.
Input
144, 2
Output
12.0 1.4142 12 4.0
Approach
- Use
math.sqrt(), ormath.isqrt()for a whole-number root.
Solution
import math print(math.sqrt(144))print(round(math.sqrt(2), 4))print(math.isqrt(150))print(16 ** 0.5)Output
12.0 1.4142 12 4.0
Line by line
Line 3
sqrt always returns a float.
Line 5
isqrt returns the whole-number part of the root (12 for 150).
Line 6
Raising to the power 0.5 also gives the square root.
Learn the concept
New to this topic? Read the lesson, then come back.