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 Dates and Times in Python (2014) Let's Build a Timed Quiz App Taking The Quiz

Tucker Fischer
Tucker Fischer
10,517 Points

Summary function is not printing

The program runs questions but at the end does not print the summary.

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)(num1, num2)
        self.questions.append(question)


def take_quiz(self):
    self.start_time = datetime.datetime.now()
    for question in self.questions:
        self.answers.append(self.ask(question))
    else:
        self.end_time = datetime.datetime.now()
    return self.summary


def ask(self, question):
    correct = False
    question_start = datetime.datetime.now()
    answer = input (question.text +' = ')
    if answer == str(question.answer):
        correct = True
    question_end = datetime.datetime.now()
    return correct, question_end - question_start


def total_correct(self):
    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("It took you {} seconds total".format(
            (self.edn_time - self.start_time).seconds
        ))

Quiz().take_quiz()

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Tucker Fischer! It looks like you forgot the parentheses where you are calling the summary method. Right now it's returning a reference to the method instead of returning what is returned by running the method. Inside your take_quiz method you have:

return self.summary # this references the method

But you meant:

return self.summary() # this calls/executes the method

Hope this helps! :sparkles:

justlevy
justlevy
6,325 Points

Also, in your summary method, check the variable spelling for self.end_time.

print("It took you {} seconds total".format(
            (self.edn_time - self.start_time).seconds
        ))