Python Program to Find the Square Root


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

The square root of a number is a value that when multiplied by itself gives back the original number. For example, 3 is a square root of 9, because 3 × 3 = 9


Python Code :

The below Python program calculates the square root of a number using the math module:

import math

num = float(input("Enter a number: "))
sqrt = math.sqrt(num)

print("The square root of", num, "is", sqrt)

This program prompts the user to enter a number, then uses the math.sqrt() function to calculate the square root of that number. The result is stored in a variable called sqrt, and then printed to the console.

Note that we convert the input number to a float using float(input()) to handle cases where the user enters a decimal number.

You can save this code as a file with a .py extension (e.g. square_root.py) and run it using Python.

Alternatively, you can run the code in the Python interpreter directly by typing the code line by line in the terminal or command prompt.


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co