Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


TypeError: 'list' object is not callable

# -*- coding: utf-8 -*-
Created on Fri Aug 11 12:11:06 2017

@author: User
import datetime
import random
from questions import Add, Multiply

class Quiz:
    questions = []
    answers = []
    correct = []

    def __init__(self):
        question_types = (Add, Multiply)
        #generate 10 random questions
        for _ in range(5):
            num1 = random.randint(1,50)
            num2 = random.randint(1,50)
            question = random.choice(question_types)(num1,num2)
            #add this questions to self.questions

    def take_quiz(self):
        #log the start time
        self.start_time = datetime.datetime.now()
        #ask all the questions
        for question in self.questions:
            self.end_time = datetime.datetime.now()
        #log if they got the questions right
        #log the end time 
        #show the summary
        return self.summary()

    def ask(self, question):
        correct = 0
        question_start = datetime.datetime.now()
        #log the start time
        answer = input(question.text + " = ")
        #capture the answer
        #check the answer
        if answer == str(question.answer):
            correct +=1 
        #log the end time
        question_end = datetime.datetime.now()
        #if the answer's right, send back True
        #otherwise False
        #send back the elapsed time too
        return correct, question_end - question_start

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

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

#print (smth.questions[0].text)
#print (smth.ques tions[0].answer)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,094 Points

Can provide complete details on the error message. It usually include the line number where the error occurred. Thanks!

After 5 tries, i've an error TypeError: 'list' object is not callable. Please see below:

47 * 2 = 94

22 + 13 = 33

44 * 21 = 4

16 * 11 = 4

43 + 10 = 4
Traceback (most recent call last):

  File "<ipython-input-1-e0dc703efda7>", line 71, in <module>

  File "<ipython-input-1-e0dc703efda7>", line 38, in take_quiz
    return self.summary()

  File "<ipython-input-1-e0dc703efda7>", line 66, in summary
    print("You've got {} from {} right".format(self.correct(), len(self.questions)))

TypeError: 'list' object is not callable

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,094 Points

Remove the parens after self.correct. It is a list and with parens, the code is trying to call the list as a function. But as the error says 'list' object is not callable.

print("You've got {} from {} right".format(self.correct, len(self.questions)))