新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:計算數(shù)字平方根
創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)公司2013年至今,先為富民等服務建站,富民等地企業(yè),進行企業(yè)商務咨詢服務。為富民企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
用一個例子寫一個 Python 程序,用 sqrt 和冪函數(shù)求一個數(shù)的平方根。
這個程序允許用戶輸入任何數(shù)字。接下來,這個 Python 平方根程序使用名為 sqrt() 的數(shù)學函數(shù)找到該數(shù)字的平方根。
# 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
使用冪()的數(shù)字平方根
在本 Python 平方根程序中,我們使用 pow()函數(shù)來求一個數(shù)的平方根。記住,√數(shù)=數(shù)
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)) 網(wǎng)頁題目:Python程序:計算數(shù)字平方根
本文來源:http://m.fisionsoft.com.cn/article/cojggip.html


咨詢
建站咨詢
