老爸的工具箱之:心算练习
想要这么个玩意很久了:
电脑自动出加减乘除的题目,并通过语音的方式读出
理由很简单,现在出去买点小菜、水果啥的,找零钱的时候的大脑老是短路,就是算不出来,明显不如以前好用了。弄这么个玩意练练脑子,当然,以后买个啥的算的比谁都快也不错~~~
电脑出题比较容易,弄些随机数就能搞定;语音很重要,如果题目是显示出来的,那就容易多了,不能达到练习心算的效果。但是对于语音这块觉得有点麻烦,本来想自己录下来一个数字,加减乘除的发音然后在程序里播放,但因为嫌麻烦也就一直没搞。
这两天写了些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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述