Skip to content

Instantly share code, notes, and snippets.

@gousiosg
Created November 10, 2018 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gousiosg/8bc092b4a8656f1aa9d68b4aef87319e to your computer and use it in GitHub Desktop.
Save gousiosg/8bc092b4a8656f1aa9d68b4aef87319e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# (c) 2018 Georgios Gousios <gousiosg@gmail.com>
#
# 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