我是靠谱客的博主 乐观煎蛋,这篇文章主要介绍python输入半径计算公式_Python:09设计Circle类包括圆心半径、颜色属性,编写类方法计算周长与面积(2种方法)...,现在分享给大家,希望可以做个参考。

设计一个Circle类,包括圆心位置、半径、颜色属性。编写构造方法进行属性初始化,编写类方法计算周长与面积。

方法一

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.Ge

最后

以上就是乐观煎蛋最近收集整理的关于python输入半径计算公式_Python:09设计Circle类包括圆心半径、颜色属性,编写类方法计算周长与面积(2种方法)...的全部内容,更多相关python输入半径计算公式_Python:09设计Circle类包括圆心半径、颜色属性,编写类方法计算周长与面积(2种方法)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(105)

评论列表共有 0 条评论

立即
投稿
返回
顶部