python输入半径计算公式_Python:09设计Circle类包括圆心半径、颜色属性,编写类方法计算周长与面积(2种方法)...
設(shè)計(jì)一個(gè)Circle類,包括圓心位置、半徑、顏色屬性。編寫構(gòu)造方法進(jìn)行屬性初始化,編寫類方法計(jì)算周長與面積。
方法一
class Circle:
location=(0,0)
r=0
color=""
def __init__(self):
self.location=(100,100)
self.r=10
self.color="white"
def GetGirth(self):
PI=3.14
print("圓的周長:")
print(2*PI*self.r)
def GetArea(self):
PI=3.14
print("圓的面積")
print(PI*self.r*self.r)
myCircle=Circle()
myCircle.GetGirth()
myCircle.GetArea()
#方法二
class Circle:
def __init__(self,location,r,color):
self.location =location
self.r=r
self.color=color
def GetGirth(self):
return 2*3.14*self.r
def GetArea(self):
return 3.14*self.r*self.r
myCircle=Circle((200,200),10,"紅色")
print("圓的周長=%0.2f"%(myCircle.GetGirth()))
print("圓的面積=%0.2f"%(myCircle.GetArea()))
ice_software涵
發(fā)布了174 篇原創(chuàng)文章 · 獲贊 442 · 訪問量 11萬+
私信
關(guān)注
標(biāo)簽:Python,self,09,color,def,print,Circle,myCircle
來源: https://blog.csdn.net/weixin_44015669/article/details/104102145
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的python输入半径计算公式_Python:09设计Circle类包括圆心半径、颜色属性,编写类方法计算周长与面积(2种方法)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫今日头条_python爬
- 下一篇: python右对齐格式化输出_Pytho