Saturday 31 January 2015

Terrific Times Table Test Tool with SL4A

School test practice for my daughter has again given me inspiration for a Geek project (after my previous project to create a spellings test tool).  At my daughter's school they're currently conducting quick-fire times oral table tests where the teacher reads out 50-odd times table questions in quick succession.  In helping my eldest practice for these tests we found:

  1. It's hard to be really random in the questions you ask and you often end up focusing on one times table (e.g. the twelves).
  2. It's hard to keep track of the questions you ask and the associated answers.
  3. It's hard to make sure you are keeping to an appropriate pace.

So I solved this challenge using SL4A, my favourite scripting language for Android handsets.

Using Python and the Android API binding I could implement the following features:

Feature 1: Generate random times table questions using the randint method from the random module:

from random import randint
FirstVal = randint (3,12)
SecondVal = randint (3,12) 

...the 3 and 12 attributes means the random numbers are always within the range 3 to 12 (inclusive).  This means no super easy 1 and 2 times tables.

Feature 2: Form strings to speak and to print to screen and then say the times table:

#Form strings to print and say
SayString = str (FirstVal) + ' times ' + str (SecondVal)
PrintString = str (i) + ': ' + SayString + ' = ' + str (FirstVal * SecondVal)
print PrintString

#Speak the times table
droid.ttsSpeak(SayString)

Feature 3: Compute a variable delay after speaking ones times table and then speaking the next. Easier calculations get a shorter delay, harder calculations get a longer delay:

  #Compute a different delay depending on the complexity of the times table
  TheAnswer = FirstVal * SecondVal
  if TheAnswer < 60:
    TheDelay = 3
  elif TheAnswer > 90:
    TheDelay = 5
  else:
    TheDelay = 4
  time.sleep (TheDelay)

...it's arguable that the complexity of a times table is not 100% correlated with how large the number is (e.g. 7 * 8 is harder than 10 * 10) but it's a good general rule of thumb.

Feature 4: Having an on-screen record of all the questions.  These can be used for post-test marking of my daughter's answers:



Here's a video of it in action:



...and here's all the code.  The great things for me is that this tool, which makes life just a little bit easier, took a mere 20 minutes to write, test and debug.  SL4A is epic!

import android
from random import randint
import time

#Create a Droid object and speak a welcome message
droid = android.Android()
droid.ttsSpeak('Hi. get ready for a terrific times table test')

#Sleep - gives time for the TTS application to initiate
time.sleep (10)

#Loop for as many times as required
for i in range (1,51):
  #Form the two values for the times table
  FirstVal = randint (3,12)
  SecondVal = randint (3,12)
    
  #Form strings to print and say
  SayString = str (FirstVal) + ' times ' + str (SecondVal)
  PrintString = str (i) + ': ' + SayString + ' = ' + str (FirstVal * SecondVal)
  print PrintString
    
  #Speak the times table
  droid.ttsSpeak(SayString)
    
  #Compute a different delay depending on the complexity of the times table
  TheAnswer = FirstVal * SecondVal
  
  if TheAnswer < 60:
    TheDelay = 3
  elif TheAnswer > 90:
    TheDelay = 5
  else:
    TheDelay = 4
  time.sleep (TheDelay)

2 comments:

  1. I think this app is great!

    It probably has a wider application that the spelling test as tables are constant, whereas the word-sets for spelling would have to keep changing to suit ability.

    So why not package and publish on Play Store?

    Its got to be worth £1 to any parents with small children.

    ReplyDelete
  2. That's a great idea! Many thanks.

    Creating an apk is definitely on my to do list. Alas time is the great enemy. I spent longer writing the blog posts than coding the times table and spelling test tools...

    ReplyDelete