Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("highscore.txt", "r") as f:
- highscore = f.read()
- highscore = int(highscore)
- print("The highscore previously was ")
- highscore = 0
- while True:
- score = 0
- print("Welcome to the Maths Quiz")
- print("Can you answer three questions and score maximum points?")
- print("Question 1: What is the product of 2x2x2?")
- print("Question 2: What is the product of 3x3x3?")
- print("Question 3> What is the product of 5x5x5?")
- answer = int(input("Your answer :>>"))
- if answer == 8:
- print("Correct")
- score = score + 1
- print("Your scores is ", score)
- else:
- print("The correct answer is 8")
- print ("Your score is ", score)
- answer = int(input("Your answer :>>"))
- if answer == 27:
- print("Correct")
- score = score + 1
- print("Your scores is ", score)
- else:
- print("The correct answer is 27")
- print ("Your score is ", score)
- answer = int(input("Your answer :>>"))
- if answer == 125:
- print("Correct")
- score = score + 1
- print("Your scores is ", score)
- else:
- print("The correct answer is 125")
- print ("Your score is ", score)
- if score >= highscore:
- highscore = score
- print("The highscore is " + str(highscore))
- if score >= highscore:
- highscore = score
- print("You have set a new highscore")
- with open("highscore.txt", "w") as f:
- f.write(str(highscore))
- else:
- print("Better luck next time")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement