【发布时间】:2015-11-26 19:32:17
【问题描述】:
我们尝试使用 easygui、按钮框创建一个多选菜单。 We have tired if, else and elif statements but whenever selecting one of the math subject options, it always takes the player to addition/will ask玩家加法问题。 我们不确定是否是 if/else/elif 语句的问题(我们希望 elif 能够工作),或者是否是 Figure1/Figure2 的另一个问题,我们似乎无法寻找。
这是我们的编码示例,我们只向您展示了主题选择菜单、加法和减法问题。 (希望为您节省所有时间,因为所有科目都相同,它们只是更改为 DivisionAnswers 和 MultiplicationAnswers 等) 但我们专注于科目选择中的问题强>
Subject = easygui.buttonbox ("What maths subject would you like to test?", choices = ["Addition","Subtraction","Multiplication","Division"])
if "Addition":
easygui.msgbox ("Please enter the correct answer to earn a point, there are 10 questions in this quiz")
for number in range(0,10):
Figure1 = random.randrange(0,11)
Figure2 = random.randrange(0,11)
PlayerAnswer = easygui.enterbox ("What is " +str(Figure1)+ " + " +str(Figure2)+ "?")
if int(PlayerAnswer) == Figure1 + Figure2:
AdditionAnswers += 1
easygui.msgbox ("Correct! Your score is "+str(AdditionAnswers))
print(AdditionAnswers)#To see if game is keeping count of questions asked
else:
AdditionAnswers += 0
IncorrectAnswers += 1
easygui.msgbox ("Sorry, incorrect! Your score is still "+str(AdditionAnswers))
print(AdditionAnswers)#To see if game is keeping count of questions asked
easygui.msgbox ("You scored " +str(AdditionAnswers)+ " out of 10")
print(AdditionAnswers) #To check if programme is calculating score correctly
print(IncorrectAnswers)
elif "Subtraction":
easygui.msgbox ("Please enter the correct answer to earn a point, there are 10 questions in this quiz")
for number in range(0,10):
Figure1 = random.randrange(0,11)
Figure2 = random.randrange(0,11)
PlayerAnswer = easygui.enterbox ("What is " +str(Figure1)+ " - " +str(Figure2)+ "?")
if int(PlayerAnswer) == Figure1 - Figure2:
SubtractionAnswers += 1
easygui.msgbox ("Correct! Your score is "+str(SubtractionAnswers))
print(SubtractionAnswers)#To see if game is keeping count of questions asked
else:
SubtractionAnswers+= 0
IncorrectAnswers += 1
easygui.msgbox ("Sorry, incorrect! Your score is still "+str(SubtractionAnswers))
print(SubtractionAnswers)#To see if game is keeping count of questions asked
easygui.msgbox ("You scored " +str(SubtractionAnswers)+ " out of 10")
print(SubtractionAnswers) #To check if programme is calculating score correctly
print(IncorrectAnswers)
感谢您给我们的任何帮助或建议,非常感谢,因为我们都刚刚开始学习 Python 编程。
编辑~ 它似乎绕过了所有其他主题并直接添加,无论选择什么主题
【问题讨论】:
标签: python if-statement random easygui