Created
November 10, 2018 20:21
-
-
Save gousiosg/8bc092b4a8656f1aa9d68b4aef87319e to your computer and use it in GitHub Desktop.
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/env python | |
# (c) 2018 Georgios Gousios <[email protected]> | |
# | |
# Barebones linear equation solving trainer | |
from __future__ import division | |
from random import randint | |
import codecs | |
import sys | |
UTF8Writer = codecs.getwriter('utf8') | |
sys.stdout = UTF8Writer(sys.stdout) | |
tries = 1 | |
success = 0 | |
errors = 0 | |
while True: | |
a = randint(1, 5) | |
x = randint(1, 5) | |
b = randint(1, 8) | |
y = a * x + b | |
r = 0 | |
while r != x: | |
try: | |
r = int(input("%dX + %d = %d. X = " % (a, b, y))) | |
tries += 1 | |
if r == x: | |
success += 1 | |
print(u'\U0001F600') | |
else: | |
errors += 1 | |
print(u'\u2639') | |
except KeyboardInterrupt: | |
print() | |
print(u'\U0001F44D success rate: %f %%' % (success/tries * 100)) | |
exit(0) | |
except SyntaxError: | |
print("Please input a number") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment