Skip to content

Instantly share code, notes, and snippets.

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 adamgen/1699f614fcc87727677362d704ad51aa to your computer and use it in GitHub Desktop.
Save adamgen/1699f614fcc87727677362d704ad51aa to your computer and use it in GitHub Desktop.
import numpy as np
def is_int(s):
try:
int(s)
return True
except ValueError:
return False
def generate_conditions():
global m1, m2, m3;
m1 = np.random.randint(5, size=(2, 4))
m2 = np.random.randint(5, size=(4, 1))
m3 = np.dot(m1, m2)
attempts = 0
phase = 0
def print_conditions():
print m1
print "*"
print m2
print "="
# print str(m3[0][0]) + ", " + str(m3[1][0])
def wait_until_correct_input(correct_input, last_attmpt=""):
if last_attmpt != "":
global attempts
attempts += 1
print_conditions()
print "level " + str(phase) + " wrong attempts - " + str(attempts)
if last_attmpt == "hint":
print "hint: " + str(correct_input)
input_recieved = raw_input()
if not (is_int(input_recieved) and int(input_recieved) == correct_input):
wait_until_correct_input(correct_input, input_recieved)
else:
global phase
phase += 1
def play_game():
generate_conditions()
for correct in m3:
wait_until_correct_input(correct[0])
play_again = raw_input("type to play again")
if play_again == "y":
play_game()
play_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment