vendredi 29 avril 2016

Randint in class

So I have created this class to randomly assign potential answers to buttons in a quiz I am making. It puts the text of the answer as one of three buttons named answer1, answer2 and answer3. It also saves which one the correct answer is. The problem Im having is everty time I press a button, it resets which answer is the correct one. Does anyone know what Im doing wrong?

question1 = ["The RES building was originally an egg farm... but in what        year was it built?", "1930", "1890", "1945"]
question2 = ["How many chickens did the egg farm hold?", "50,000", "2,500", "25,000"]
question3 = ["How many visitors has RES had since 2004?", "Over 20,000", "3,000", "15,000"]
question4 = ["What does borehole cooling use to cool the RES building?", "Water", "Air", "Oil"]
question5 = ["What are the solar panels at RES used for?", "Electricity and Heating", "Electricity", "To get more sunlight in"]
question6 = ["How many meters squared are the solar panels at RES?", "170", "45", "250"]
question7 = ["How long does it take to earn back the cost of the solar panels?", "8 years", "2 years", "15 years"]
question8 = ["What is the best direction for solar panels to face?", "South", "East", "West"]
question9 = ["What is the scientific name for a solar panel?", "Photovoltaic Cell", "Solar Transformer", "Solar Farm"]
question10 = ["How tall is RES's wind turbine from the floor to the tip?", "50m", "30m", "120m"]
question11 = ["How many houses could the RES turbine power per year?", "30-40", "5-10", "60-70"]
question12 = ["Which is the fastest growing energy market?", "Wind", "Coal", "Solar"]
question13 = ["How tall is a typical turbine RES installs?", "125m", "35m", "70m"]
question14 = ["What proportion of the time does a wind turbine generate electricity?", "70 - 90%", "50%", "10 - 25%"]
question15 = ["How many cubic meters of water can the RES heat store hold?", "1400", "120", "2600"]
question16 = ["What is the name for organic material used as fuel?", "Biomass", "Wood", "Oil"]
question17 = ["What is the other name for 'miscanthus', the crop RES grows?", "Elephant Grass", "Hippo Weed", "Bamboo"]
question18 = ["How efficient at burning fuel is the biomass heater at RES?", "90%", "12%", "47%"]

n = 1
quiz = []
while n < 18:
    quiz.append(eval("question" + str(n)))
    n += 1

class Quiz:

    def __init__(self, question):
        self.question = question
        actual = random.randint(1, 3)
        possible = [1, 2, 3]
        possible.pop(actual-1)
        self.actual = actual
        self.possible = possible

    def show(self):
        question = quiz[self.question].pop(0)
        questionDisplay.config(text=question)
        correct = quiz[self.question].pop(0)
        incorrectA = quiz[self.question].pop(0)
        incorrectB = quiz[self.question].pop(0)

        #actual is correct answer, possible is incorrect answers


        correctButton = "answer"+str(self.actual)
        print(correctButton)
        eval(correctButton).config(text=correct)
        incorrect1 = "answer" + str(self.possible.pop())
        eval(incorrect1).config(text=incorrectA)
        incorrect2 = "answer" + str(self.possible.pop())
        eval(incorrect2).config(text=incorrectB)

    def check(self, button):
        global SCORE
        correct = "answer" + str(self.actual)
        print(correct)
        if button == correct:
            SCORE += 1
            print(SCORE)
            questionDisplay.config(text="CORRECT!")
        else:
            questionDisplay.config(text="INCORRECT!")
        time.sleep(1)




Aucun commentaire:

Enregistrer un commentaire