dimanche 25 octobre 2015

How to have a random number as a variable

I am making a maths game for a school assessment, I am needing my programme to put two random numbers into an equation that the players of the game will answer. I need the programme to calculate the random numbers so that they are different for each equation and each time the player plays the game, as it has to be looped 10 times. Also, my menu where the game asks the players if they would like to play, addition, subtraction etc. is not being recognised. Thankyou in advance for your help.

import easygui
import random
#Childs Literacy Game
#Charlotte 03/09/2015

#Declare Constants and Variables
CorrectAnswers = 0
IncorrectAnswer = 0
playOn = 0
Random = random.randrange(10) 

while playOn != "Yes":
    playOn = easygui.buttonbox ("Hey there, are you ready to test your maths skills?", choices = ["Yes"])
if "Yes":
    PlayerName = easygui.enterbox ("Before we begin what's your name?")

def menu():
    Subject = easygui.buttonbox ("Hi there " +PlayerName +"What maths subject would you like to test?", choices = ["Addition" "Subtraction" "Multiplication" "Divison"])
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):
 PlayerAnswer = easygui.buttonbox ("What is" +Random+ "+" +Random+ "?")
if PlayerAnswer == "Random + Random":
        CorrectAnswers += 1
        easygui.msgbox ("Correct! Your score is " +str(CorrectAnswers))
else:
    CorrectAnswers += 0
    IncorrectAnswers += 1
    easygui.msgbox ("Sorry, incorrect! Your score is "+str(CorrectAnswers))
print(CorrectAnswers) #To check if programme is calculating score correctly
print(IncorrectAnswers)
menu()
if "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):
    PlayerAnswer = easygui.buttonbox ("What is" +Random+ "-" +Random+ "?")
if PlayerAnswer == "Random - Random":
        CorrectAnswers += 1
        easygui.msgbox ("Correct! Your score is " +str(CorrectAnswers))
else:
    CorrectAnswers += 0
    IncorrectAnswers += 1
    easygui.msgbox ("Sorry, incorrect! Your score is "+str(CorrectAnswers))
print(CorrectAnswers) #To check if programme is calculating score correctly
print(IncorrectAnswers)
menu()




Aucun commentaire:

Enregistrer un commentaire