Square Root of a Number
Compute square root using built-in math functions and user input.
- Import the
mathmodule. - Read a number from the user.
- Use
math.sqrt()to calculate the square root. - Print the result.
import math
num = float(input("Enter a number: "))
sqrt_val = math.sqrt(num)
print(f"Square root of {num} is {sqrt_val}")Enter a number: 16
Square root of 16.0 is 4.0