Last active
April 29, 2020 14:28
-
-
Save NISH1001/d75c55892cc0b6357791c0e2a545b6da to your computer and use it in GitHub Desktop.
random sum user test
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
#!/usr/bin/env python3 | |
import random | |
def main(): | |
mn, mx = (10, 99) | |
correctness = 3 | |
correct = 0 | |
while True: | |
num1 = random.randint(mn, mx) | |
num2 = random.randint(mn, mx) | |
total = num1 + num2 | |
answer = int(input("What is " + str(num1) + " + " + str(num2) + "? ")) | |
if answer == total: | |
correct += 1 | |
print(f"Correct!You've gotten {correct} correct in a row.") | |
else: | |
# reset the counter | |
correct = 0 | |
print("Incorrect. The expected answer is " + str(total)) | |
if correct == correctness: | |
break | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment