[英]The volume of a sphere?
半徑為r的球體積為4 /3πr3。 半徑為5的球體的體積是多少? 提示:392.6錯了!
print (((4/3.0) * 3.14) * 5**3)
它給了我這個
523.333333333
怎么了???
python 2.7
沒有錯,你有正確的答案。 您可能希望使用math.pi
而不是3.14來提高答案的精確度。
>>> from __future__ import division # not necessary if using python 3
>>> 4/3*math.pi*5**3
523.59877559829886
請參閱wolfram alpha的解決方案
如果你使用地板除法而不是真正的除法,那么你將得到392.6,這就是提示的結果:
>>> 4//3*math.pi*5**3
392.69908169872411
對於那些使用版本3的人:簡單的print語句作為魅力。
print((4/3)*(22/7)*5**3)
輸出:523.8095238095237
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.