-5

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')
PRMoureu
  • 12,817
  • 6
  • 38
  • 48
  • `format()` and `round()` *return* their result. Numbers are immutable objects, they are not altered in-place. `format()` also produces a string object, not another number, and is intended to help you present the values, not to round. – Martijn Pieters Jul 30 '17 at 11:50

1 Answers1

0

format is not in-place (like any other string-related function/method in Python). You need to reassign its return value:

formatted = format(self.correct_answer, '.2f')

Keep in mind what Martijn Pieters mentioned in the comment. format returns a string, not a float.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154