Python中计算圆的周长,面积
生活随笔
收集整理的這篇文章主要介紹了
Python中计算圆的周长,面积
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
計算圓的周長,面積,代碼如下
import math #導入數學模塊radius = int(input('radius(unit: cm): ')) #輸入半徑perimeter = 2*math.pi*radius #將直徑帶入到(C=2πr)area = math.pi*radius**2 #將半徑帶入到(S=π*r*r)# 輸出結果 print(f"The perimeter of the circle is:{perimeter}cm") print(f"The area of the circle is:{area}cm")若要結果輸出為整數,可在變量”perimeter“和area前加int(),代碼如下
import math #導入數學模塊radius = int(input('radius(unit: cm): ')) #輸入半徑perimeter = 2*math.pi*radius #將直徑帶入到(C=2πr)area = math.pi*radius**2 #將半徑帶入到(S=π*r*r)# 輸出結果 print("The perimeter of the circle is:",int(perimeter),"cm") print("The area of the circle is:",int(area),"cm")總結
以上是生活随笔為你收集整理的Python中计算圆的周长,面积的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中科院博士教你如何查找外文文献
- 下一篇: 单片机的两个外围电路:复位电路和时钟电路