用户:
就在天边等待你查看:1 回复:1 评论:1 创建时间:2023-01-01T18:18:59
from random import choice,randint
from tkinter import simpledialog,messagebox,Tk
root = Tk()
root.withdraw()
def get_answer(title,question):
answer = int(simpledialog.askstring(title,question))
return answer
#小狗方程
OperationalSymbol = ['+','-','*','/']
knowingNumber = ['a','b','c','d','e','f','x','y','z']
score = 0
count = int(simpledialog.askstring('count','Enter the number of questions'))
for x in range(count):
choiceSymbol = choice(OperationalSymbol)
choiceNumber = choice(knowingNumber)
if choiceSymbol == '+':
a = randint(1,50)
b = randint(1,50)
while a >= b:
b += randint(1,50)
title = str(a) + choiceSymbol + choiceNumber +'=' + str(b)
question = choiceNumber + '=?'
Output = title+'\n'+question
solution = b - a
answer = get_answer('Ape equation',Output)
if answer == solution:
score += 1
messagebox.showinfo('Ape equation','Correct answer!')
else:
messagebox.showinfo('Ape equation','Wrong answer!')
elif choiceSymbol == '-':
a = randint(1,50)
b = randint(1,50)
title = choiceNumber + choiceSymbol + str(a) +'=' + str(b)
question = choiceNumber + '=?'
Output = title+'\n'+question
solution = b + a
answer = get_answer('Ape equation',Output)
if answer == solution:
score += 1
messagebox.showinfo('Ape equation','Correct answer!')
else:
messagebox.showinfo('Ape equation','Wrong answer!')
elif choiceSymbol == '*':
a = randint(1,50)
b = randint(1,50)
while b%a != 0 or a>b:
b += randint(1,20)
title = str(a) + choiceNumber +'=' + str(b)
question = choiceNumber + '=?'
Output = title+'\n'+question
solution = int(b / a)
answer = get_answer('Ape equation',Output)
if answer == solution:
score += 1
messagebox.showinfo('Ape equation','Correct answer!')
else:
messagebox.showinfo('Ape equation','Wrong answer!')
elif choiceSymbol == '/':
a = randint(1,50)
b = randint(1,50)
while a>b:
b += 1
title = choiceNumber + '÷' + str(a) +'=' + str(b)
question = choiceNumber + '=?'
Output = title+'\n'+question
solution = b * a
answer = get_answer('Ape equation',Output)
if answer == solution:
score += 1
messagebox.showinfo('Ape equation','Correct answer!')
else:
messagebox.showinfo('Ape equation','Wrong answer!')
finalScore = 100 / (count/score)
messagebox.showinfo('score','your score is:'+str(finalScore))
root.mainloop()