题目内容:
请定义一个Circle类,具体要求为:(1)每个Circle类对象可以存储圆心和半径信息;(2)具有设置圆心和半径的方法SetCenter和SetRadius;(3)具有计算圆面积的方法GetArea。
import math
#请在此处补充Circle类定义的代码(提示:计算圆面积时使用math.pi获取圆周率)
if __name__=='__main__':
x=eval(input()) #输入圆心的x坐标
y=eval(input()) #输入圆心的y坐标
r=eval(input()) #输入半径
c=Circle() #创建Cirle对象
c.SetCenter(x,y) #设置圆心
c.SetRadius(r) #设置半径
print('center:(%.2f,%.2f),radius:%.2f'%(c.x,c.y,c.r)) #输出圆心和半径
print('area:%.2f'%c.GetArea()) #输出面积
输入格式:
分三行输入3个数,分别表示圆心的x坐标和y坐标以及半径
输出格式:
第一行输出圆心和半径
第二行输出面积
输入样例:
2
3
4
输出样例:
center:(2.00,3.00),radius:4.00 area:50.27
时间限制:500ms内存限制:32000kb
代码:
import math
class Circle:
def __init__(self):
pass
def SetCenter(self, x, y):
self.x = x
self.y = y
def SetRadius(self, r):
self.r = r
def GetArea(self):
return math.pi*r**2
if __name__=='__main__':
x=eval(input()) #输入圆心的x坐标
y=eval(input()) #输入圆心的y坐标
r=eval(input()) #输入半径
c=Circle() #创建Cirle对象
c.SetCenter(x,y) #设置圆心
c.SetRadius(r) #设置半径
print('center:(%.2f,%.2f),radius:%.2f'%(c.x,c.y,c.r)) #输出圆心和半径
print('area:%.2f'%c.GetArea()) #输出面积
用例测试结果 | 运行时间 | 占用内存 | 提示 | 得分 |
---|---|---|---|---|
用例1通过 | 33ms | 4620kb | 1 | |
用例2通过 | 34ms | 4516kb | 1 |
本次得分/总分:2.00/2.00分