100以内四则运算练习(千纬数学app)正式版及其源码-优快云博客
有一段时间,小孩子没有用,我也没有去留意,最近拿出来给小孩子用,发现存在一个问题,就是出题是随机的,这样实际效率不高,比如出一些如1+2=3,51+5=56之类的题,这些题做久了,对运算的提升是否有作用,题库是10000多条,这些简单的题应该占比不少,也会浪费一定时间。
为此,我修改了代码,在原ys表中的cuo列,修改其用途,用于记录每答一题的时间,这个时间数据是用20秒去减去答题的秒数记录的,比如做题速度为3秒,那个这个数值就是17,也就是说数值越大说明该题的做题速度越快,这样做的目的是为了排序,按正序去排列要提取的题目,数值大即做题速度越快的题目就会沉淀在后面不会被提取出来,提取出来的是一些答题速度慢的题目。当然也要有一定的随机性,我假设全部题目都有答,那么就在答题速度慢的50道题中抽题。当然一开始的cuo的数据都是0,那么就在cuo数值较小的范围内选题,这样一圈,全部的题目都答完了,在从答题速度慢的题目选题答。我还设定当一道题答错,那么cuo会变为0,cuo也会记录答题速度最快的数据。通过这个提高孩子的运算能力。
源码如下:
from functools import partial
import toga
from toga.style.pack import COLUMN, LEFT, RIGHT, ROW, Pack
import sqlite3
import random
from time import time,sleep
from pathlib import Path
import datetime
import shutil
import miniaudio
import threading
#导入必要的库
resources_folder = Path(__file__).joinpath("../resources/").resolve()
db_filepath = resources_folder.joinpath("qwsx.db")
#测试参数1为手机,0为电脑,2为boox平板
sjcs = 1
if sjcs == 1:
sj_file = '/data/data/com.qwsx.qwsx/qwsx.db'
if Path(sj_file).exists():
db_filepath = sj_file
else:
shutil.copy(db_filepath, sj_file)
db_filepath = sj_file
elif sjcs == 2:
db_filepath = '/storage/emulated/0/Pictures/qwsx.db'
conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
c = conn.cursor()
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%Y-%m-%d")
cursor = c.execute("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='jfen'")
row = cursor.fetchone()
have_jfena = row[0]
if have_jfena == 0:
c.execute('''CREATE TABLE jfen (
jid INTEGER PRIMARY KEY AUTOINCREMENT,
rq TEXT,
jf INTEGER);
''')
conn.commit()
cursor = c.execute("SELECT count(*) FROM jfen WHERE rq='"+ formatted_date +"'")
row = cursor.fetchone()
if row[0] == 0:
query_sql = "INSERT INTO jfen (rq,jf) VALUES (?,?);"
c.execute(query_sql, (formatted_date,0,))
conn.commit()
c.close()
conn.close()
#建积分表,并插入一行今日积分
names = globals()
nd = 0
hd = 0 #回答为0为出题,回答为1为1位数答题,2为2位数答题,3为3位数答题,4为符号答题
dan = 101 #初始答案
dan1 = 0
dan2 = 0
dan3 = 0
tjcs = ''
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
#判断是不是数字
def u_jfen(jf):
if jf > 0 or (jf < 0 and globals()['cuo'] <= 1):
conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
c = conn.cursor()
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%Y-%m-%d")
cursor = c.execute("SELECT count(*) FROM jfen WHERE rq='"+ formatted_date +"'")
row = cursor.fetchone()
if row[0] ==0:
query_sql = "INSERT INTO jfen (rq,jf) VALUES (?,?);"
c.execute(query_sql, (formatted_date,0,))
conn.commit()
query_sql = "update jfen set jf = jf + ? where rq= ?"
c.execute(query_sql, (jf,formatted_date,))
conn.commit()
else:
query_sql = "update jfen set jf = jf + ? where rq= ?"
c.execute(query_sql, (jf,formatted_date,))
conn.commit()
c.close()
conn.close()
#更新积分,增加积分,中间再次判断今日的数据行是否存在是为了跨日做题不出错
def bfnum(number):
conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
c = conn.cursor()
cursor = c.execute("SELECT sc from voice where number = ?;",(number,))
row = cursor.fetchone()
sc = row[0]
c.close()
conn.close()
stream = miniaudio.stream_file(str(resources_folder.joinpath(str(number) + '.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(sc)
def bffh(fh):
if fh == '+':
stream = miniaudio.stream_file(str(resources_folder.joinpath('jia.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(0.92)
if fh == '-':
stream = miniaudio.stream_file(str(resources_folder.joinpath('jian.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(0.948)
if fh == '*':
stream = miniaudio.stream_file(str(resources_folder.joinpath('sheng.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(0.975)
if fh == '/':
stream = miniaudio.stream_file(str(resources_folder.joinpath('chu.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(0.975)
if fh == '□':
stream = miniaudio.stream_file(str(resources_folder.joinpath('duo.wav')))
with miniaudio.PlaybackDevice() as device:
device.start(stream)
sleep(1.066)
if fh == '=':
stream = miniaudio.stream_fil