Skip to content

Instantly share code, notes, and snippets.

@pschwede
Created February 11, 2011 21:17
Show Gist options
  • Save pschwede/823047 to your computer and use it in GitHub Desktop.
Save pschwede/823047 to your computer and use it in GitHub Desktop.
Uses espeak to ask user about simple arithmetic calculations and answers each question by itself after some time. Default language is German. – It has been reported to me that, making a game with it, can be great fun on parties. ;)
#!/usr/bin/env python
import random as ra
import os, time
def main(language):
ra.seed()
ops = ("+", "-", "*", "/")
equals = ("=")
comma = "point"
if (language == "german"):
ops = ("plus", "minus", "mal", "durch")
equals = ("macht", "ergibt", "ist gleich", "entspricht")
comma = (",")
while(True):
op = ra.randint(0, len(ops)-1)
a = ra.randint(1, 10+90*(op<2))
b = ra.randint(1, 10+90*(op<2))
os.system("espeak -v %s \"%i %s %i\"" % (language, a, ops[op], b)) > 0
time.sleep(7)
res = a
if op == 0:
res += b
elif op == 1:
res -= b
elif op == 2:
res *= b
else:
if res%b == 0:
res /= b
else:
res = round(res*1./b,2)
res = str(res).replace(".", comma)
os.system("espeak -v %s \"%i %s %i %s %s\"" % (language, a, ops[op], b, equals[ra.randint(0,len(equals)-1)], res)) > 0
main("german")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment