Created
August 27, 2013 11:06
-
-
Save benkaiser/6352234 to your computer and use it in GitHub Desktop.
Simple program I made for my brother to practice his multiplication and division.
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
#!/usr/bin/python | |
import random | |
def main(): | |
num_correct = 0 | |
num_incorrect = 0 | |
while True: | |
num_1 = random.randint(0, 12) | |
num_2 = random.randint(1, 12) | |
is_mult = bool(random.getrandbits(1)) | |
if is_mult: | |
answer = raw_input(str(num_1) + " x " + str(num_2) + " = ") | |
right = (num_1*num_2) | |
if int(answer) == (right): | |
# correct | |
correct = True | |
else: | |
# incorrect | |
correct = False | |
else: | |
answer = raw_input(str(num_1*num_2) + " / " + str(num_2) + " = ") | |
right = num_1 | |
if int(answer) == (right): | |
# correct | |
correct = True | |
else: | |
# incorrect | |
correct = False | |
if correct: | |
print "Great Job!" | |
num_correct += 1 | |
else: | |
print "Sorry! (correct answer was " + str(right) + ")" | |
num_incorrect += 1 | |
print "Correct " + str(num_correct) + " | Incorrect " + str(num_incorrect) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment