Advertisement
makispaiktis

MathQuestions Quiz

Apr 24th, 2019 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import random
  2.  
  3. # 1. Intro
  4. print()
  5. print("**** THIS IS A MATH QUIZ-CHALLENGE! THANKS FOR PLAYING! ****")
  6. n = int(input("Enter how many questions do you want to ask to contestants: "))
  7. print("Because this is an important challenge, please enter your names: ")
  8. name1 = input("Name of Player1: ")
  9. name2 = input("Name of Player2: ")
  10. print()
  11. print()
  12. counter1 = 0
  13. counter2 = 0
  14.  
  15. # 2. For-loop for displaying the math questions
  16. for i in range(n):
  17.     print(" **** R O U N D   " + str(i+1) + " ****")
  18.     # Player1
  19.     r1 = random.randint(1, 200)
  20.     r2 = random.randint(1, 200)
  21.     answer1 = int(input("  It's " + name1 + "'s turn:   " + str(r1) + " + " + str(r2) + " = "))
  22.     result1 = r1 + r2
  23.     if answer1 == result1:
  24.         counter1 += 1
  25.         print("YOU ARE RIGHT!")
  26.     else:
  27.         print("WRONG ANSWER, SORRY!")
  28.     # Player2
  29.     r3 = random.randint(1, 200)
  30.     r4 = random.randint(1, 200)
  31.     answer2 = int(input("  It's " + name1 + "'s turn:   " + str(r3) + " + " + str(r4) + " = "))
  32.     result2 = r3 + r4
  33.     if answer2 == result2:
  34.         counter2 += 1
  35.         print("YOU ARE RIGHT!")
  36.     else:
  37.         print("WRONG ANSWER, SORRY!")
  38.     print()
  39.  
  40. print("* * * * * * RESULTS * * * * * * *")
  41. print(name1 + ": " + str(counter1) + " correct answers.")
  42. print(name2 + ": " + str(counter2) + " correct answers.")
  43. print()
  44. if counter1 > counter2:
  45.     print(name1 + ", wins! ")
  46.     print(name2 + ", better luck next time...")
  47. elif counter1 < counter1:
  48.     print(name2 + ", wins! ")
  49.     print(name1 + ", better luck next time...")
  50. else:
  51.     print("It's a tier guys.")
  52.     print(name1 + " and " + name2 + " you are in the same level in maths!")
  53. print("* * * * * * * * * * * * * * * *")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement