79633984

Date: 2025-05-22 14:46:37
Score: 0.5
Natty:
Report link

I have managed to make it work like the following: That might not be the most effective solution but for now I make it work. Thank you so much guys for your hints. It works like I wanted it to.

 def highest_score(self):
        try:
            with open("score.csv", "r") as file:
                data = file.readlines()[0]
                highscore = int(data)
                if self.score > highscore:                
                    with open("score.csv", 'w') as file:
                        file.write(str(self.score))
                    self.text_score.write(f"Game over!\nYour highest score is: {self.score}", align="center", font=("Arial", 20, "normal"))
                else:
                    with open("score.csv", 'w') as file:
                        file.write(str(highscore))
                    self.text_score.write(f"Game over!\nYour highest score is: {highscore}", align="center", font=("Arial", 20, "normal"))
                                 
        except FileNotFoundError:
            with open("score.csv", 'w') as file:
                file.write(str(self.score))
                self.text_score.write(f"Score: {self.score}", align="center", font=("Arial", 20, 'normal'))
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: DAVE LOVE