【两道Python的题关于类的2定义类Circle,要求具有-查字典问答网
分类选择

来自沈沛的问题

  【两道Python的题关于类的2定义类Circle,要求具有以下方法,编写测试程序进行功能演示(文本方式即可)Circle(point,r):根据给定的圆心和半径生成一个圆,圆心的实现也请定义一个类moveto(point)】

  两道Python的题关于类的2定义类Circle,要求具有以下方法,编写测试程序进行功能演示(文本方式即可)

  Circle(point,r):根据给定的圆心和半径生成一个圆,圆心的实现也请定义一个类

  moveto(point):将圆心移到新的位置

  change_r(x):将半径重新设置为x

  get_area():获取面积

  3CreateandtestaSetclasstorepresentaclassicalset.Yoursetsshouldsupportthefollowingmethods:

  Set(elements)Createaset(elementsistheinitiallistofitemsintheset).

  addElement(x)Addsxtotheset.

  deleteElement(x)Removesxfromtheset.

  member(x)Returnstrueifxisintheset.

  intersection(set2)Returnsanewsetcontainingjustthoseelementsthatarecommontothissetandset2.

  union(set2)Returnsanewsetcontainingallofelementsthatareinthisset,set2,orboth.

  subtract(set2)Returnsanewsetcontainingalltheelementsofthissetthatarenotinset2.

  注意:有些方法有返回值,有些没有

  表示看不懂……不会写

4回答
2020-05-22 13:40
我要回答
请先登录
金远平

  建议你还是自己写一下试试,

  遇到不明白的地方,再拿来问;

  要不然,大家不是很乐意这样提问的.

2020-05-22 13:44:24
沈沛

  可以谢谢

2020-05-22 13:45:56
金远平

  import math

  class point:

  def __init__(self,x,y):

  self.x=x

  self.y=y

  class Circle:

  def __init__ (self,point,r):

  self.point=point

  self.r=r

  def moveto(self,point):

  self.point=point

  def change_r(self,x):

  self.r=x

  def get_area(self):

  return math.pi*self.r*self.r

  c=Circle(point(1,2),10)

  print(c.get_area()) 我的编译器是python3.2的

2020-05-22 13:49:29
沈沛

  跟我写的几乎一样但是我有几个问题:

  1,Circle类里面的point是直接调用的第一个point类吗?这种格式不会错吧

  2,题目说的要生成一个圆,要不要画出来……

  3,编写测试程序进行功能演示这句是啥意思……感觉定义了之后没什么好掩饰的东西……

2020-05-22 13:52:48

最新问答

推荐文章

猜你喜欢

附近的人在看

推荐阅读

拓展阅读

  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  •