import tkinter as t
from tkinter import simpledialog, messagebox
from random import randint as r
from time import *
score = 0
stage = None
def zdy():
def op5_n_command():
mquestions([int(op1_1.get()), int(op1_2.get())], [int(op3_1.get()), int(op3_2.get())], op2_x.get(),
stage='自定义', times=int(op4_x.get()))
tk = t.Tk()
op1_n = t.Label(tk, text='操作数1范围')
op1_1 = t.Entry(tk, width=12)
op1_m = t.Label(tk, text='~')
op1_2 = t.Entry(tk, width=12)
op2_n = t.Label(tk, text='符号')
op2_x = t.Spinbox(tk, width=10, values=('+', '-', 'x', '÷', '^'), wrap=True, justify='left')
op3_n = t.Label(tk, text='操作数2范围')
op3_1 = t.Entry(tk, width=12)
op3_m = t.Label(tk, text='~')
op3_2 = t.Entry(tk, width=12)
op4_n = t.Label(tk, text='题数')
op4_x = t.Spinbox(tk, values=tuple(range(5, 100)), justify='left', width=10)
op5_n = t.Button(tk, text='开始', width=10, command=op5_n_command)
op5_m = t.Button(tk, text='退出', width=10, command=quit)
op1_n.grid(row=0, column=0)
op1_1.grid(row=0, column=1)
op1_m.grid(row=0, column=2)
op1_2.grid(row=0, column=3)
op2_n.grid(row=1, column=0)
op2_x.grid(row=1, column=1)
op3_n.grid(row=2, column=0)
op3_1.grid(row=2, column=1)
op3_m.grid(row=2, column=2)
op3_2.grid(row=2, column=3)
op4_n.grid(row=3, column=0)
op4_x.grid(row=3, column=1)
op5_n.grid(row=4, column=1)
op5_m.grid(row=4, column=3)
tk.mainloop()
def check_level(stage):
if stage == 1:
questions(1, 6, '+', 1)
elif stage == 2:
questions(1, 6, '+', 2)
elif stage == 3:
questions(1, 6, '-', 3)
elif stage == 4:
questions(1, 6, '-', 4)
elif stage == 5:
questions(1, 10, '+', 5)
elif stage == 6:
questions(1, 11, '+', 6)
elif stage == 7:
questions(1, 11, '+', 7)
elif stage == 8:
questions(1, 10, '-', 8)
elif stage == 9:
questions(1, 10, '-', 9)
elif stage == 10:
questions(1, 11, '-', 10)
elif stage == 11:
questions(1, 11, '-', 11)
elif stage == 12:
questions(1, 6, '*', 12)
elif stage == 13:
questions(1, 11, '*', 13)
elif stage == 14:
questions(1, 11, '*', 14)
elif stage == 15:
questions(1, 11, '*', 15)
elif stage == 16:
questions(1, 11, '/', 16)
elif stage == 17:
questions(1, 11, '/', 17)
elif stage == 18:
questions(1, 11, '/', 18)
elif stage == 19:
questions(1, 16, '/', 19)
elif stage == 20:
questions(1, 16, '/', 20)
elif stage == 21:
questions(10, 16, '*', 21)
elif stage == 22:
questions(10, 16, '*', 22)
elif stage == 23:
questions(10, 51, '+', 23)
elif stage == 24:
questions(10, 51, '-', 24)
elif stage == 25:
questions(1, 101, '+', 25)
elif stage == 26:
questions(1, 101, '-', 26)
elif stage == 27:
questions(1, 101, '-', 27)
elif stage == 28:
questions(15, 21, '*', 28)
elif stage == 29:
questions(15, 21, '*', 29)
elif stage == 30:
questions(10, 21, '*', 30)
elif stage == 31:
questions(10, 21, '*', 31)
elif stage == 32:
questions(100, 1001, '+', 32)
elif stage == 33:
questions(100, 1001, '-', 33)
elif stage == 34:
questions(10, 1001, '+', 34)
elif stage == 35:
questions(10, 1001, '-', 35)
elif stage == 36:
questions(1, 1001, '+', 36)
elif stage == 37:
questions(1, 1001, '+', 37)
elif stage == 38:
questions(1, 1001, '-', 38)
elif stage == 39:
questions(1, 1001, '-', 39)
elif stage == 40:
questions(1, 1001, '-', 40)
elif stage == 41:
messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
for i in range(20):
a = random(1)
show_question(str(a) + '²=?', a ** 2, 5)
stage += 1
check_level(stage)
elif stage == 42:
messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
for i in range(20):
a = random(1) + 10
show_question(str(a) + '²=?', a ** 2, 5)
stage += 1
check_level(stage)
elif stage == 43:
questions(10, 30, '*', 43)
elif stage == 44:
questions(1, 30, '*', 44)
elif stage == 45:
questions(1, 31, '*', 45)
elif stage == 46:
questions(1, 31, '*', 46)
elif stage == 47:
questions(4, 400, '/', 47)
elif stage == 48:
questions(4, 400, '/', 48)
elif stage == 49:
questions(1, 400, '/', 49)
elif stage == 50:
questions(1, 100000000, '+', 50)
elif stage == 51:
questions(1, 100000000, '+', 51)
elif stage == 52:
questions(1, 999999999, '+', 52)
elif stage == 53:
questions(1, 999999999, '+', 53)
elif stage == 54:
questions(1, 100000000, '-', 54)
elif stage == 55:
questions(1, 100000000, '-', 55)
elif stage == 56:
questions(1, 999999999, '-', 56)
elif stage == 57:
questions(1, 999999999, '-', 57)
elif stage == 58:
questions(1, 999999999, '-', 58)
elif stage == 59:
questions(1, 50, '*', 59)
elif stage == 60:
questions(1, 50, '*', 60)
elif stage == 61:
questions(1, 50, '*', 61)
elif stage == 62:
questions(1, 50, '*', 62)
elif stage == 63:
questions(1, 10000, '/', 63)
elif stage == 64:
questions(1, 10000, '/', 64)
elif stage == 65:
questions(1, 100000, '/', 65)
elif stage == 66:
questions(1, 1000000, '/', 66)
elif stage == 67:
questions(1, 100, '*', 67)
elif stage == 68:
questions(1, 1000, '*', 68)
elif stage == 69:
questions(1, 100000, '*', 69)
elif stage == 70:
questions(1, 10000000, '*', False)
else:
messagebox.showinfo('End', 'The End')
def show_question(question, answer, points=4):
global score
next = True
times = 1
points += 1
while next == True and times <= 3:
try:
ANSWER = int(simpledialog.askstring('Question', question))
except:
messagebox.showerror('Value Error', 'Please input an integer.')
ANSWER = 0
break
if int(answer) == int(ANSWER):
messagebox.showinfo('Correct', 'Correct answer')
next = False
score += (points - times)
else:
messagebox.showwarning('Wrong', 'Wrong answer,you have %d chances' % (3 - times))
times += 1
sleep(0.5)
def questions(enter1, enter2, sign='*', stage=stage, times=20):
global score
if bool(stage):
messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
else:
messagebox.showinfo('Stage', 'FINAL STAGE')
if sign == '+':
while score <= 80:
for i in range(times):
a = r(enter1, enter2)
b = r(enter1, enter2)
show_question((str(a) + '+' + str(b) + '=?'), a + b, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
elif sign == '-':
while score <= 80:
for i in range(times):
a = r(enter1, enter2)
b = r(enter1, enter2)
big = max(a, b)
small = min(a, b)
show_question((str(big) + '-' + str(small) + '=?'), big - small, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
elif sign == '*':
while score <= 80:
for i in range(times):
a = r(enter1, enter2)
b = r(enter1, enter2)
show_question((str(a) + '×' + str(b) + '=?'), a * b, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
else:
while score <= 80:
for i in range(times):
a = r(enter1, enter2)
b = r(enter1, enter2)
show_question((str(a) + '÷' + str(b) + '=?'), round(a / b), 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
score = 0
stage += 1
check_level(stage)
def mquestions(enter1, enter2, sign='*', stage=stage, times=20):
global score
messagebox.showinfo('Stage', ('Stage ' + str(stage) + ', (if it\'s a division, please input an integer.)'))
if sign == '+':
for i in range(times):
a = r(enter1[0], enter1[1])
b = r(enter2[0], enter2[1])
show_question((str(a) + '+' + str(b) + '=?'), a + b, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
elif sign == '-':
for i in range(times):
a = r(enter1[0], enter1[1])
b = r(enter2[0], enter2[1])
big = max(a, b)
small = min(a, b)
show_question((str(big) + '-' + str(small) + '=?'), big - small, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
elif sign == 'x':
for i in range(times):
a = r(enter1[0], enter1[1])
b = r(enter2[0], enter2[1])
show_question((str(a) + '×' + str(b) + '=?'), a * b, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
elif sign == '÷':
for i in range(times):
a = r(enter1[0], enter1[0])
b = r(enter2[0], enter2[0])
show_question((str(a) + '÷' + str(b) + '=?'), round(a / b), 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
else:
for i in range(times):
a = r(enter1[0], enter1[0])
b = r(enter2[0], enter2[0])
show_question((str(a) + '^' + str(b) + '=?'), a ** b, 5)
sleep(1.5)
messagebox.showinfo('Points', 'Your point is %s points.' % score)
score = 0
def level():
global stage
hard = simpledialog.askstring('Hard',
'Would you like to choose which level: L1, L2 ,L3, L4, L5, L6, L7, FINAL,Z(自定义)?')
hard = hard.upper()
if hard == 'L1':
stage = 1
elif hard == 'L2':
stage = 12
elif hard == 'L3':
stage = 21
elif hard == 'L4':
stage = 41
elif hard == 'L5':
stage = 50
elif hard == 'L6':
stage = 59
elif hard == 'L7':
stage = 63
elif hard == 'FINAL':
stage = 70
elif hard == 'Z':
zdy()
else:
messagebox.showwarning('Warning', 'It\'s not a level.')
level()
level()
check_level(stage)剪贴板
剪贴板 yt3jkcqy
剪贴板信息
剪贴板信息
- 收录
- 更新