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 The Quiz Class

Oti Oritsejafor
Oti Oritsejafor
3,281 Points

Indentation problem

I get the error in Workspaces :

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/treehouse/workspace/quiz.py", line 28
def ask(self, question):
^
IndentationError: expected an indented block

When I type in ">>> from quiz import Quiz"

I can't seem to find the error, I even tried the already written one in the Workspaces and it still gives me the same error

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)      
        #Generate 10 random questions from 1 to 10
        #Add these questions into self.questions

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

    def ask(self, question):                                    LINE 28
        #log the start time
        #capture the answer
        #check the answer
        #if the answer's right, send back True
        #otherwise, send back false
        #send back the elapsed time

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

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

The indentation error is due to the take_quiz() function definition. The colon at the end of the line indicates the start of a code block. Since the function only contains comments, no actual statements are found until reaching the function definition of ask(). This is interpreted as in indentation error.

To fix the indention error, add a pass statement after the comments. It can be used until you have actual statements in the function definition.