日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python輸入圓半徑,計算圓周長和面積的實現方式_python

作者:iFulling ? 更新時間: 2023-01-20 編程語言

Python輸入圓半徑,計算圓周長和面積

用 Python 編寫程序:輸入圓半徑,計算圓周長和面積

"""
功能: 輸入圓半徑,計算圓周長和面積
作者: Fulling
時間: 2021年10月15日
"""

import math

# 輸入部分
r = float(input('輸入圓的半徑:'))

# 處理部分
c = 2 * math.pi * r
s = math.pi * r ** 2

# 輸出部分
print('該圓的周長是:%.2f' % c)
print('該圓的面積是:%.2f' % s)

輸出結果:

輸入圓的半徑:3
該圓的周長是:18.85
該圓的面積是:28.27

python面向對象的方法計算圓的周長和面積

class yuan:
? ? def __init__(self,r):
? ? ? ?self.r=r
? ? ? ?print("圓的半徑為:",self.r)
? ? def get_circle(self):
? ? ? ? print("圓的周長為:",2*3.14*self.r)
? ? def get_area(self):
? ? ? ? print("圓的面積為",(3.14*self.r**2))

yuan1=yuan(3)以半徑為三舉例
yuan1.get_circle()
yuan1.get_area()

總結

原文鏈接:https://blog.csdn.net/realoser/article/details/121526417

欄目分類
最近更新