Advertisement
Botontam

Highscore_file

Jun 7th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. with open("highscore.txt", "r") as f:
  2. highscore = f.read()
  3. highscore = int(highscore)
  4. print("The highscore previously was ")
  5.  
  6.  
  7. highscore = 0
  8. while True:
  9. score = 0
  10. print("Welcome to the Maths Quiz")
  11. print("Can you answer three questions and score maximum points?")
  12. print("Question 1: What is the product of 2x2x2?")
  13. print("Question 2: What is the product of 3x3x3?")
  14. print("Question 3> What is the product of 5x5x5?")
  15. answer = int(input("Your answer :>>"))
  16. if answer == 8:
  17. print("Correct")
  18. score = score + 1
  19. print("Your scores is ", score)
  20. else:
  21. print("The correct answer is 8")
  22. print ("Your score is ", score)
  23. answer = int(input("Your answer :>>"))
  24. if answer == 27:
  25. print("Correct")
  26. score = score + 1
  27. print("Your scores is ", score)
  28. else:
  29. print("The correct answer is 27")
  30. print ("Your score is ", score)
  31. answer = int(input("Your answer :>>"))
  32. if answer == 125:
  33. print("Correct")
  34. score = score + 1
  35. print("Your scores is ", score)
  36. else:
  37. print("The correct answer is 125")
  38. print ("Your score is ", score)
  39.  
  40. if score >= highscore:
  41. highscore = score
  42. print("The highscore is " + str(highscore))
  43.  
  44. if score >= highscore:
  45. highscore = score
  46. print("You have set a new highscore")
  47. with open("highscore.txt", "w") as f:
  48. f.write(str(highscore))
  49. else:
  50. print("Better luck next time")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement