用一個例子寫一個 Python 程序,用 sqrt 和冪函數求一個數的平方根。
這個程序允許用戶輸入任何數字。接下來,這個 Python 平方根程序使用名為 sqrt() 的數學函數找到該數字的平方根。
# Python Program to find Square root of a Number
import math
number = float(input(" Please Enter any numeric Value : "))
squareRoot = math.sqrt(number)
print("The Square Root of a Given Number {0} = {1}".format(number, squareRoot))
Please Enter any numeric Value : 64
The Square Root of a Given Number 64.0 = 8.0
使用冪()的數字平方根
在本 Python 平方根程序中,我們使用 pow()函數來求一個數的平方根。記住,√數=數
import math
number = float(input(" Please Enter any numeric Value : "))
squareRoot = math.pow(number, 0.5)
print("The Square Root of a Given Number {0} = {1}".format(number, squareRoot))
原創文章,作者:FF5J0,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/130870.html