[kde-edu]: Simple arithmetic apps

John Lamb kde-edu@kde.org
Thu, 30 Jan 2003 19:04:30 +0000


Is there anything out there that does tests basic mental arithmetic 
skills (addition, subtraction, multiplication tables) for 6-8 year olds?

To illustrate this, I knocked together a python script (below), but it 
would be nice to have something like this in Qt/KDE. I guess it wouldn't 
take even me long to write something if there's nothing already.

-- 
JDL
--
#!/usr/bin/python
import whrandom
def test_int( s ):
     if len( s ) == 0:
         return 1
     for char in s:
         if char not in "0123456789":
             return 1
     return 0
def get_int( x ):
     text = raw_input( x )
     while test_int( text ):
         print
         print "You must type a number."
         text = raw_input( x )
     return int( text )
print; print; print
print "*************** My Sums Test *****************"
print; print;
score = 0
while score < 10:
     if whrandom.randint( 0, 1 ):
         a = whrandom.randint( 0, 9 )
         b = whrandom.randint( 0, 9 )
         r = a + b
         c = get_int( "What is %d + %d? " % ( a, b ) )
     else:
         #subtraction
         a = whrandom.randint( 0, 18 )
         b = whrandom.randint( max( a - 9, 0 ), min( a, 9 ) )
         r = a - b
         c = get_int( "What is %d - %d? " % ( a, b ) )
     if c == r:
         score = score + 1
         print "Correct: your score is %d" % score
     else:
         score = 0
         print "The correct answer was %d. You must start again." % r
     print
print; print "Well done! You got ten correct answers in a row."
print; print