# 1_8_maths_game.py

Apr 14th, 2021
668
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # 1_8_maths_game_2.py
2. # Have a go at adding more questions.
3. # Also save a running log of the Score & Question numbers.
4. #   Would prefer to log the mark for each question
5. # Also save the High score
6.
7. high_score = 0
8. fw = open("1_8_high_score.txt", "w")  # Overwrite. Must contain something eg '0'
9. fa = open("1_8_score.txt", "a")  # write Append
10. fa.write("Score" + ", Question \n")
11.
12. while True:  # means loop forever.
13.     score = 0
14.     print("Welcome to the Maths Quiz")
15.     print("Can you answer three questions and score maximum points?")
16. # Q1
17.     print("Question 1: What is the product of 2x2x2 ?")
19.
21.         print("Correct")
22.         score = score + 1
24.         fa.write(str(score) + ", \t#1\n")
25.     else:
26.         print("Incorrect, the answer is 8")
28.         fa.write(str(score) + ", \t#1\n")
29. # Q2
30.     print("Question 2: What is the product of 3x3 ?")
32.
34.         print("Correct")
35.         score = score + 1
37.         fa.write(str(score) + ", \t#2\n")
38.     else:
39.         print("Incorrect, the answer is 9")
41.         fa.write(str(score) + ", \t#2\n")
42. # Q3
43.     print("Question 3: What is the product of 5x2 ?")
45.
47.         print("Correct")
48.         score = score + 1
50.         fa.write(str(score) + ", \t#3\n")
51.     else:
52.         print("Incorrect, the answer is 10")
54.         fa.write(str(score) + ", \t#3\n")
55.
56.     if score > high_score:
57.         high_score = score
58.     print("The high score is", str(high_score))
59.
60.     fw.write(str(high_score) + "\n")
61.
62.     fa.close()
63.     fw.close()
64.
65.     break
66.
67. # Save running score ...OK
68. # Save high_score ... OK
69.
71. # "Question 1: What is the product of 2x2x2 ?", 8
72. # "Question 2: What is the product of 3x3 ?",   9
73. # "Question 3: What is the product of 5x2 ?",  10
RAW Paste Data