Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

The quiz class

import datetime import random

from questions import Add, Multiply

class Quiz: questions = [] answers = []

def __init__(self):
    question_type = (Add, Multiply)
    # generate 10 random questions with numbers from 1 to 10
    for _ in range(10):
        num1 = random.randint(1, 10)
        num2 = random.randint(1, 10)
        questions = random.choice(question_type)(num1, num2)
        # add these questions into self.questions
        self.questions.append(question)



def take_quiz(self):
    # log the start time
    # ask all of the questions
    # log if they got the question right
    # log the end time
    # show a summary
    pass

def ask(self, question):
    # log the start time
    # capture the answer
    # check the answer
    # log the end time
    # if the answer's right, send back True
    # otherwise, send back False
    # send back the elapsed time, too
    pass


    def total_correct(self):
        # return the total number of correct answers
        total = 0
        for answer in self.answers:
            if answer [0]:
                total += 1
        return total

def summary(self):
    print('You got {} out of {} right.'.format(
            self.total_correct, len(self.questions)
    ))
    # print how many you got right and the total # of questions. 5/10
    # print the total time for the quiz: 30 seconds!
    print('It took you {} seconds total.'.format(
            (self.end_time-self.start_time).seconds
    ))

line 19 in init self.questions.append(question) NameError: name 'question' is not defined

I don't know where I'm going wrong.

1 Answer

Steven Parker
Steven Parker
243,656 Points

A link to the quiz/challenge/video would be helpful, and it would be VERY helpful if the code were blockquoted correctly (see Markdown Cheatsheet below :arrow_heading_down:).

But just at first glance this caught my eye:

        questions = random.choice(question_type)(num1, num2)

:point_right: Should that assignment be to "question" (singular) instead?.