2015-11-26 2 views
0

Мы пытаемся создать меню с несколькими вариантами, используя easygui, buttonbox. Мы устали , если еще и Элифа заявления, но всякий раз, когда выбор одного из вариантов по математике при условии, что всегда берет игрок в дополнение/зададут плеер аддитивные вопросы. Мы не уверены, является ли проблема с статусом if/else/elif (мы ожидали бы, что elif будет работать), или если это еще одна проблема с Figure1/Figure2, которую мы не можем найти.Multi choice, easygui buttonbox

Вот пример нашего кодирования, мы только покажем вам проблемы выбора объектов, сложения и вычитания. (мы надеемся сохранить вас все время, как все предметы одинаковы, они просто быть изменено на 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) 

Thankyou за любую помощь или предложения, которые вы можете нам дать, это очень ценится, поскольку мы все начинаем изучать программирование на питоне.

EDIT ~ кажется, обойти все другие темы и направиться прямо к сложению независимо от того, какой предмет выбран

ответ

0

Условный/elifs, кажется, в порядке. Сравнение неверно. Должно быть:

if Subject == "Addition": 

Вы все-таки хранить свой выбор из buttonbox в переменной с именем Subject
Применить то же самое для остальных. Удачи ! PS. общая концепция состоит в том, чтобы назвать переменные с строчными буквами. Верхний регистр зарезервирован для классов. EDIT: Исправлен код для вас. Массивные ошибки отступов.

import easygui 
import random 
AdditionAnswers = 0 
IncorrectAnswers = 0 
SubtractionAnswers = 0 
Subject = easygui.buttonbox ("What maths subject would you like to test?", choices = ["Addition","Subtraction","Multiplication","Division"]) 
if Subject == "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 Subject == "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) 
+0

Я сделал это для всех, но он все еще спрашивает нас аддитивные вопросы, когда мы щелкаем по другим темам * редактировать * кажется, обойти все остальные предметы и идет прямо к сложению независимо от того, какого предмета выбран – BabyPythons

+0

только что отредактировал мой ответ. ваши отступы были ВСЕ по всему месту –

+0

Ops thankyou так много! (звучит, как я, я слишком ленив или полностью забываю отступать ровно половину времени!) Спасибо, так много за вашу помощь, это много значит! – BabyPythons

Смежные вопросы