Hi I am learning python and there is these two code snippets but I keep getting an error when I try to run the program.

# survey.py

class AnonymousSurvey():
    # Collect anonymous answers to a survey question.

    def __init__(self, question):
        # Store a question, and prepare to responses.
        self.question = question
        self.responses = []

    def show_question(self):
        # Show the survey question.

    def store_response(self, new_response):
        # Store a single response for the survey

    def show_results(self):
        # Show all responses that have been given
        print("Survey results: ")
        for response in responses:
            print('- ' + response)

# language_survey.py

from survey import AnonymousSurvey

# Define a question, and make a survey
question = "What language did you first learn to speak?"
my_survey = AnonymousSurvey(question)

# Show the question, and store responses to the question.
print("Enter q at any time to quit.\n")

while True:
    response = input("Language: ")
    if response == 'q':

# Show the survey results
print("\nThank you to everyone who participated in the Survey!")
This is the error message I get:
Traceback (most recent call last):
  File "../Documents/Python Code/language_survey.py", line 8, in <module>
  File "../Documents/Python Code/survey.py", line 11, in show_question
NameError: name 'question' is not defined

Process finished with exit code 1

Thanks alot for the help!!!

line 13 should be print(self.question)
and similar mistake in the line 22

Thanks Alot AndrisP the error was also present in the book.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.