#.此程式將找到用戶給定半徑的圓的面積和周長。
匯入數學
radius=int(input('輸入一個半徑的數字'))
area=math.pi半徑2
print('圓面積%f'%area)
周長= 2 math.pi半徑
print('圓的周長%f'%周長)
uj5u.com熱心網友回復:
代替%f,%.2f在列印到小數點后兩位時使用。
uj5u.com熱心網友回復:
Python 有一個 round 關鍵字。像這樣使用它:
round(3.14159, 2)
>>> 3.14
或者,您可以在列印時使用 python f-strings 進行舍入,如下所示:
num = 3.14159
print(f'{num:.2f}')
>>> 3.14
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/323930.html
標籤:Python 列表 python-2.7
上一篇:向量中缺少幾個元素
