jeudi 26 novembre 2015

Multi choice, easygui buttonbox menu

We trying to create a multi choice menu using easygui, buttonbox. 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 the player addition questions. We are not sure whether it is a problem with the if/else/elif statment (we would've expected elif to work) or if it is another problem with the Figure1/Figure2 we can not seem to find.

Here is an example of our coding, we have only shown you the subject selection menu, addition, and subtraction problems. (to hopefully save you all time as all the subjects are the same, they are just be changed to DivisionAnswers and MultiplicationAnswers etc. ) But we are focusing on the problem within the subject selection

   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 for any help or suggestions you can give us, it is greatly appreciated as we are all just beginning to learn python programming.

Aucun commentaire:

Enregistrer un commentaire