1
I’m studying the book Python on a Crash Course And everything was going great until now. After testing the codes on pages 324 and 325 (which are a module and a program that uses it), I was surprised that nothing works.
What to do to fix this code and make it work?
Here is the module survey.py
:
class AnonymousSurvey():
def __init__(self, question): #Aqui Esta em vermelho(problema)
#Armazena uma pergunta e se prepara para armazenar asrespostas.
self.question = question
self.responses = []
def show_question(self):
#Mostra a pergunta da pesquisa.
print(question) #Aqui também esta (aparente problema)
def store_response(self, new_response):
#Armazena uma única resposta da pesquisa.
self.responses.append(new_response)
def show_results(self):
#Mostra todas as respostas dadas.
print("Survey results:")
for response in responses:
print('- ' + response)
And here’s the little program that uses the module above:
from Modulo_Survey import AnonymousSurvey
# Define uma pergunta e cria uma pesquisa
question = 'What language did you first learn to speak?'
my_survey = AnonymousSurvey(question)
# Mostra a pergunta e armazena as respostas à pergunta
my_survey.show_question()
print("Enter 'q' at any time to quit.\n")
while True:
response = input("Language: ")
if response == 'q':
break
my_survey.store_response(response)
# Exibe os resultados da pesquisa
print("\nThank you to everyone who participated in the survey!")
my_survey.show_results()
What should I do to make it work??
– Nameless Man
I recommend studying a little more about object orientation, what’s wrong with your code are just object orientation concepts, as you said is a study material
– Wictor Chaves