Here’s an example Python code to find the square root of a number:
import math # Take input from the user num = float(input("Enter a number: ")) # Find the square root using the math module square_root = math.sqrt(num) # Print the square root print("The square root of", num, "is", square_root)
In this code, we first import the math
module, which provides several mathematical functions, including the sqrt()
function for finding the square root of a number.
We then use the input()
function to prompt the user to enter a number. We convert the user input to a float using the float()
function and assign it to the variable num
.
Next, we use the math.sqrt()
function to find the square root of num
and assign the result to the variable square_root
.
Finally, we use the print()
function to output the square root of num
.
When you run this code, it should prompt you to enter a number. Once you enter a number and press enter, it should output the square root of that number. For example:
Enter a number: 25 The square root of 25.0 is 5.0
Note that you can replace 25
with any other number you want to find the square root of.