Posts Tagged ‘Programs’

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.

PyS60 and N95 Accelerometer example

Wednesday, August 26th, 2009

                              
Here’s a little script to get you going with interfacing the N95′s accelerometer in PyS60 with the AXYZ module. Nothing ground braking here, but possibly a good starting point if you’re a bit stumped.

#Title   : Accelerometer Test
#Author  : Mike Terzza http://terzza.com
#Summary : An example application to demo interfacing with the accelerometer of an N95 with PyS60
#Version : 0.1
#Date    : 26/01/08
#

import e32
import axyz

def main(x,y,z):
    if x < -30:
        print "#"
    elif x > 30:
        print " " * 60, "#"
    else:
        if y > 0:
            barY = (y / 8) + 1
        else:
            barY = 1
        barX = (x + 30)- (barY / 2)
        print " " * barX, "#" * barY

axyz.connect(main)
e32.ao_sleep(15)
axyz.disconnect()