Advertisement
timber101

GameMaths

Jan 11th, 2021
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1. highscore = 0  #  initalising the high score
  2.  
  3. while True:  #  keep going till false (an infinite loop)
  4.   score = 0 #  initalising the score for each loop of the while loop
  5.  
  6.   print("Welcome to the math quiz")  # play the game instructions
  7.   print("Can you answer 3 questions??")
  8.  
  9.   #Q1
  10.   print("\nQ1.  What is the product of 2 x 2 x 2 ? >>")
  11.  
  12.   answer = int(input("Your answer>> ")) # get the answer and turn it inot an integer and save it tovariable answer
  13.  
  14.   # Q1 checking
  15.   if answer == 8: ### what about adding in error trapping
  16.     print("yay, well done, correct")
  17.     score +=1 # increase score by one (same as score = score +1)
  18.     print(f"your score is {score}") # other ways of printing our
  19.   else:
  20.     print("sorry thats not correct :(")
  21.     print("your score ", score)
  22.  
  23.   #high score beaten??
  24.   if score > highscore:
  25.     highscore = score
  26.   print(f"The current high score is>> {highscore}")
  27.  
  28.   # Q2
  29.   print("\nQ2.  What is the 4 MOD 2 ? (4%2) >>")
  30.  
  31.   answer = int(input("Your answer>> ")) # get the answer and turn it inot an integer and save it tovariable answer
  32.  
  33.   # Q2 checking
  34.   if answer == 0: ### what about adding in error trapping
  35.     print("yay, well done, splendido")
  36.     score +=1 # increase score by one (same as score = score +1)
  37.     print(f"your score is {score}") # other ways of printing our
  38.   else:
  39.     print("sorry thats not correct :(")
  40.     print("your score ", score)
  41.  
  42.   #high score beaten??
  43.   if score > highscore:
  44.     highscore = score
  45.   print(f"The current high score is>> {highscore}")
  46.  
  47.   # Q3
  48.   print("\nQ3.  What is 7//3 ?  >>")
  49.  
  50.   answer = int(input("Your answer>> ")) # get the answer and turn it inot an integer and save it tovariable answer
  51.  
  52.   # Q3 checking
  53.   if answer == 1: ### what about adding in error trapping
  54.     print("yay, well done, yabadabadoo")
  55.     score +=1 # increase score by one (same as score = score +1)
  56.     print(f"your score is {score}") # other ways of printing our
  57.   else:
  58.     print("sorry thats not correct :(")
  59.     print("your score ", score)
  60.  
  61.   #high score beaten??
  62.   if score > highscore:
  63.     highscore = score
  64.   print(f"The current high score is>> {highscore}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement