Skip to content

Instantly share code, notes, and snippets.

@rebkwok
Created November 10, 2014 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebkwok/29ac202109de27f69d1f to your computer and use it in GitHub Desktop.
Save rebkwok/29ac202109de27f69d1f to your computer and use it in GitHub Desktop.
Holly's first python program
import random
score = 0
print("============================================================")
print("WELCOME TO HOLLY'S MATHS GAME!")
print("============================================================")
name = input("What is your name?\n")
print("Hello", name)
print("Good luck!\n")
input("Press Enter to start.")
print()
for i in range(1, 11):
number1 = random.choice(range(1, 11))
number2 = random.choice(range(1, 21))
question = str(number1) + " + " + str(number2) + " = ?\n"
print("Question", i)
sum_answer = input(question)
try:
if int(sum_answer) == number1 + number2:
print('Correct!')
score = score + 1
else:
print('Incorrect! The right answer is', number1 + number2)
except ValueError:
print('Incorrect! The right answer is', number1 + number2)
print()
print()
print("============================================================")
if score == 10:
print("Awesome!! Perfect Score! Your score is", score, "out of 10!")
else:
print("Good try! Keep practising. Your score is", score, "out of 10.")
print("============================================================")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment