Python Dates and Times in Python Let's Build a Timed Quiz App The Quiz Class

This is not working

When I run it I get this

treehouse:~/workspace$ python                                                           
Python 3.6.4 (default, Nov 19 2019, 17:12:46)                                           
[GCC 5.4.0 20160609] on linux                                                           
Type "help", "copyright", "credits" or "license" for more information.                  
>>> from quiz import Quiz                                                               
>>> quiz1 = Quiz()                                                                      
>>> quiz1.answers                                                                       
[]                                                                                      
>>> quiz1.questions                                                                     
[<class 'questions.Multiply'>, <class 'questions.Add'>, <class 'questions.Add'>, <class 
'questions.Add'>, <class 'questions.Multiply'>, <class 'questions.Add'>, <class 'questio
ns.Multiply'>, <class 'questions.Add'>, <class 'questions.Multiply'>, <class 'questions.
Multiply'>]                                                                             
>>> quiz1.questions[0].text                                                             
>>>

As you can see it gives back nothing. Here is my code

import datetime
import random

from questions import Add, Multiply


class Quiz:
    questions = []
    answers = []

    def __init__(self):
        question_types = [Add, Multiply]
        for _ in range(10):
            num1 = random.randint(1, 10)
            num2 = random.randint(1, 10)
            question = random.choice(question_types)
            self.questions.append(question)


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


    def total_correct(self):
        total = 0
        for answer in self.answers:
            if answer[0] == True:
                total += 1


    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 summary(self):
        print(f"You got {self.total_correct()}/{self.questions}")
        print(f"It took you a total of {(self.end_time.start_time)} seconds")

3 Answers

Josh Keenan
Josh Keenan
19,306 Points

You don't need any .text at the end.

When I did that this happened

treehouse:~/workspace$ python                                                                    
Python 3.6.4 (default, Nov 19 2019, 17:12:46)                                                    
[GCC 5.4.0 20160609] on linux                                                                    
Type "help", "copyright", "credits" or "license" for more information.                           
>>> from quiz import Quiz                                                                        
>>> quiz1 = Quiz()                                                                               
>>> quiz1.answers                                                                                
[]                                                                                               
>>> quiz1.questions                                                                              
[<class 'questions.Multiply'>, <class 'questions.Add'>, <class 'questions.Multiply'>, <class 'que
stions.Multiply'>, <class 'questions.Add'>, <class 'questions.Add'>, <class 'questions.Multiply'>
, <class 'questions.Multiply'>, <class 'questions.Add'>, <class 'questions.Multiply'>]           
>>> quiz1.questions[0]                                                                           
<class 'questions.Multiply'>            
Josh Keenan
Josh Keenan
19,306 Points

Print it out, if it doesn't come out how you want you should write the __str__ for your class so it is output correctly.

It's still not working