如何添加字符串方法?

2024-09-27 07:20:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个在线课程来提高python的水平,其中一个问题是没有通过我不知道是代码还是站点解释器错了

我得到了以下指示

Add a __str__ method to GameScore that returns the score in the string "Player 1: 5; Player 2: 10", using the correct values from self.score. self.score is a tuple with Player 1's score and Player 2's score like (5, 10). You do not need to define self.score. It comes from the Game class.

这是我的密码

from game import Game

class GameScore(Game):
   def __Str__(self):
       return "Player 1: %s Player 2: %s" %(self.score[0], self.score[1])

我得到这个错误

 Expected "Player 1: 5; Player 2: 2". Got "<__main__.GameScore object at 0x7f56c2a04b38>".

Tags: theto代码fromselfaddgame站点

热门问题