Skip to content

Instantly share code, notes, and snippets.

@NISH1001
Last active April 29, 2020 14:28
Show Gist options
  • Save NISH1001/d75c55892cc0b6357791c0e2a545b6da to your computer and use it in GitHub Desktop.
Save NISH1001/d75c55892cc0b6357791c0e2a545b6da to your computer and use it in GitHub Desktop.
random sum user test
#!/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