The square root of a number is a value that, when multiplied by itself, gives the original number.
import math
def calculate_square_root(num):
return math.sqrt(num)
# Taking input from the user
number = float(input("Enter a number to calculate its square root: "))
square_root = calculate_square_root(number)
print("Square root of", number, "is", square_root)
Enter a number to calculate its square root: 25
Square root of 25 is 5.0
Enter a number to calculate its square root: 2
Square root of 2 is 1.4142135623730951
The function calculate_square_root(num)
takes a number num
as input and returns its square root using Python's built-in math.sqrt()
function.
The example usage section demonstrates how to take input from the user, calculate the square root, and print the result.