@Encoders

Ошибка в коде. В чём проблема?

Ошибка:
Traceback (most recent call last):
  File "Language_survey.py", line 4, in <module>
    my_servey.show_question()
  File "D:\Geany\python_world\survey.py", line 6, in show_question
    print(question)
NameError: name 'question' is not defined


Код
from survey import AnonymousSurvey
question = "What language did you first learn to speak ? "
my_servey = AnonymousSurvey(question)
my_servey.show_question()
print("Enter 'q' at any time to quit.\n")
while True :
    response = input('Language: ')
    if response == 'q':
        break
    my_servey.store_response(response)
print("\nThank you to everyone who pacticipated in the survey!")
my_servey.show_results()


Модуль:
class AnonymousSurvey():
    def __init__(self,question):
        self.question = question
        self.response = []
    def show_question(self):
        print(question)
    def store_response(self,new_response):
        self.response.append(new_response)
    def show_results(self):
        print("Survey results:")
        for response in responses :
            print("- " + response)
  • Вопрос задан
  • 194 просмотра
Решения вопроса 1
@trofimovdev
Python
def show_question(self):
        print(self.question)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы