老爸的工具箱之:心算练习
想要这么个玩意很久了:
电脑自动出加减乘除的题目,并通过语音的方式读出
理由很简单,现在出去买点小菜、水果啥的,找零钱的时候的大脑老是短路,就是算不出来,明显不如以前好用了。弄这么个玩意练练脑子,当然,以后买个啥的算的比谁都快也不错~~~
电脑出题比较容易,弄些随机数就能搞定;语音很重要,如果题目是显示出来的,那就容易多了,不能达到练习心算的效果。但是对于语音这块觉得有点麻烦,本来想自己录下来一个数字,加减乘除的发音然后在程序里播放,但因为嫌麻烦也就一直没搞。
这两天写了些VB的代码,突然想起以前有个用vbs直接说"I Love you"的脚本,查了下发现这个发音引擎正好解决了这个问题,不过,是英文的。但对于我这种善于安慰自己的人,很快把这个缺点变成了优点:
不但练习了对英语数字的听力水平,也锻炼了快速的心算能力,一举两得!
自己无聊的时候玩玩还是不错的,东西虽然简单,但要真想快速反应并计算,还是有些挑战的。这东西给我女儿用还早了点,但是感觉将来还是可能用到的,不如就先归在这个系列里,占一下女儿的光~~~
附代码,拷到一个文本文件并重命名为xxx.vbs,双击运行即可:
'
' This is a simple and funny vb script to practise your:
' 1. English listening of numbers
' 2. Swift calculation of 2 numbers
' You can adjust parameters to change difficulty, as default it only includes + and - operators
' for numbers between 0 - 100
'
' Author: Baiyan Huang
' Date: 10/20/2010
'
'==============================Main==============================
Dim bContinue
bContinue = True
While bContinue
' Generate expression and read aloud!
Dim op1, op2, op
op1 = GetOperand()
op2 = GetOperand()
op = GetOperator()
Dim strExp
strExp = op1 & op & op2 & "="
CreateObject("SAPI.SpVoice").Speak strExp
' Calculate the final result
Dim result
If op = "plus" then
result = op1 + op2
Elseif op = "minus" then
result = op1 - op2
Elseif op = "multiply" then
result = op1 * op2
Elseif op = "divided by" then
result = op1 / op2
End If
' Print the expression and result in a clearer manner
strExp = Replace(strExp, "plus", "+")
strExp = Replace(strExp, "minus", "-")
strExp = Replace(strExp, "multiply", "*")
strExp = Replace(strExp, "divided by", "/")
bContinue = MsgBox(strExp & result & vbCrLf & "Click Ok to continue!", vbOKCancel) <> vbCancel
WEnd
'================Utility Functions=======================
Function GetRandomNum(lowerbound, upperbound)
call Randomize()
GetRandomNum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Function
Function GetOperand()
GetOperand = GetRandomNum(1, 100) ' 0 - 100
End Function
Function GetOperator()
Dim operators(3)
operators(0) = "plus"
operators(1) = "minus"
operators(2) = "multiply"
operators(3) = "divided by"
Dim Index
Index = GetRandomNum(0, 1) ' Only include + and - for now
GetOperator = operators(Index)
End Function
' This is a simple and funny vb script to practise your:
' 1. English listening of numbers
' 2. Swift calculation of 2 numbers
' You can adjust parameters to change difficulty, as default it only includes + and - operators
' for numbers between 0 - 100
'
' Author: Baiyan Huang
' Date: 10/20/2010
'
'==============================Main==============================
Dim bContinue
bContinue = True
While bContinue
' Generate expression and read aloud!
Dim op1, op2, op
op1 = GetOperand()
op2 = GetOperand()
op = GetOperator()
Dim strExp
strExp = op1 & op & op2 & "="
CreateObject("SAPI.SpVoice").Speak strExp
' Calculate the final result
Dim result
If op = "plus" then
result = op1 + op2
Elseif op = "minus" then
result = op1 - op2
Elseif op = "multiply" then
result = op1 * op2
Elseif op = "divided by" then
result = op1 / op2
End If
' Print the expression and result in a clearer manner
strExp = Replace(strExp, "plus", "+")
strExp = Replace(strExp, "minus", "-")
strExp = Replace(strExp, "multiply", "*")
strExp = Replace(strExp, "divided by", "/")
bContinue = MsgBox(strExp & result & vbCrLf & "Click Ok to continue!", vbOKCancel) <> vbCancel
WEnd
'================Utility Functions=======================
Function GetRandomNum(lowerbound, upperbound)
call Randomize()
GetRandomNum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Function
Function GetOperand()
GetOperand = GetRandomNum(1, 100) ' 0 - 100
End Function
Function GetOperator()
Dim operators(3)
operators(0) = "plus"
operators(1) = "minus"
operators(2) = "multiply"
operators(3) = "divided by"
Dim Index
Index = GetRandomNum(0, 1) ' Only include + and - for now
GetOperator = operators(Index)
End Function