I am trying to round a self.correct_answer = Smth. * Smth.
I tried round(self.correct_answer, 2)
and several different format(self.correct_answer, '.2f')
type things.
Is it because of the 'self.'?
self.correct_answer = self.numbers1[self.number1] / self.numbers2[self.number2]
format(self.correct_answer, '.2f')
答案 0 :(得分:0)
format
不在原地(就像Python中任何其他与字符串相关的函数/方法)。您需要重新分配其返回值:
formatted = format(self.correct_answer, '.2f')
请记住Martijn Pieters在评论中提到的内容。 format
返回一个字符串,而不是一个浮点数。