事先道歉,但我是蟒蛇的初学者,而且还在学习。我遇到了这个问题,学生在比赛中每赚50分,就会在他们的信息中添加1颗星。但我似乎做不到,这是我的代码;
class points:
def __init__ (self, studentname, points, star):
self.studentname = studentname
self.points = points
self.star = star
def play (self, totalpoints):
self.points += totalpoints
#every time the students score 50, they will have plus 1 star
if self.points == 50:
self.star += 1
def displayInfo (self):
print (self.studentname)
print(self.points)
print(self.star)
student1 = points("Ana", 0, 0)
student2 = points("Sandra", 0, 0)
student1.displayInfo()
student2.displayInfo() #will display their information before playing
student1.play(10)
student2.play(5)
student1.play(20)
student2.play(10)
student1.play(30)
student2.play(30)
student1.play(10)
student2.play(5)
student1.play(20)
student2.play(10)
student1.play(30)
student2.play(30)
student1.displayInfo()
student2.displayInfo() #will display their information after playing发布于 2021-09-06 05:39:04
当一个学生到达时,你只会添加一颗星,正好是50分,再也不会了。在play()方法中,您可以做的是更新玩家每次添加点数时拥有的星星数,如下所示:
def play(self, totalpoints):
self.points += totalpoints
self.star = self.points // 50https://stackoverflow.com/questions/69069526
复制相似问题