Created
November 10, 2014 20:34
-
-
Save rebkwok/29ac202109de27f69d1f to your computer and use it in GitHub Desktop.
Holly's first python program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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