Created
April 7, 2019 18:42
-
-
Save Ceasar/f7bf1b2e9691e58b1cb8ef12c0385e58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def main(): | |
while True: | |
a, b = random.randint(1, 10), random.randint(1, 10) | |
expr = "{} + {}".format(a, b) | |
print "What is {}?".format(expr) | |
try: | |
given_answer = int(raw_input('> ')) | |
except ValueError: | |
print 'Wrong. Not a number.' | |
else: | |
right_answer = eval(expr) | |
if given_answer == right_answer: | |
print 'Correct!' | |
break | |
else: | |
print 'Wrong. The right answer was {}.'.format(right_answer) | |
print 'Game over.' | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment