Archive for September, 2009

PyS60 Brain Training

Wednesday, September 9th, 2009

                              
I recently spotted some guys playing Nintendo DSs in a departure lounge whilst waiting for their flight. I think they were playing one of the “Brain Training” style games. I decided to knock up this little script as a very bare bones brain trainer, as entertainment for the 2.5 hour flight ahead of me.

import random
import sys
import appuifw

level = appuifw.query(u"Choose level 1 or 2", "number")

rightans = 0
wrongans = 0

while True:
    small = random.randint(1, 10)
    if level == 2:
        large = random.randint(1, 100)
    else:
        large = random.randint(1, 10)

    input = appuifw.query(u"%d x %d" % (small, large), "number")

    ans = small * large
    if input == 0:
        break
    if input == ans:
        appuifw.query(u"Correct", "query")
        rightans += 1
    else:
        appuifw.query(u"Wrong.\n ans = %d" % ans, "query")
        wrongans += 1

appuifw.query(u"You correctly answered :\n%d out of %d" % (rightans, rightans + wrongans), "query")

Nothing ground breaking here, just a little fun. The idea is that it uses appuifw.query to display randomly generated multiplication sums. Easy mode (level 1) is 2 numbers no larger than 10 and harder mode (level 2) is the same but one of the numbers is no larger than 100.

On start-up, select a level. 2 for the harder mode, any other number for the easier mode. Sums will be constantly generated until you enter the number 0 which will display a final message with your score, and then exit.

A possible candidate for a full application here, but at the moment, just a time passer for a plane journey.