import
random
import
easygui
def
generate_question():
num1
=
random.randint(
1
,
10
)
num2
=
random.randint(
1
,
10
)
if
num1 < num2:
num1, num2
=
num2, num1
operator
=
random.choice([
'+'
,
'-'
])
question
=
f
"{num1} {operator} {num2}"
if
operator
=
=
'+'
:
answer
=
num1
+
num2
else
:
answer
=
num1
-
num2
return
question,
str
(answer)
def
main():
score
=
0
for
_
in
range
(
5
):
question, answer
=
generate_question()
user_input
=
easygui.enterbox(
"请计算 "
+
question
+
" 等于几"
)
if
user_input
is
not
None
and
user_input.isdigit():
if
int
(user_input)
=
=
int
(answer):
score
+
=
1
else
:
easygui.msgbox(f
"错误👜 正确答案是:{answer}"
)
else
:
easygui.msgbox(
"错误."
)
easygui.msgbox(f
"你的正确率为: {score}/5"
)
if
__name__
=
=
"__main__"
:
main()