|
survey.py
class AnonymousSurvey():
def __init__(self, question):
self.question = question
self.resp**es = []
def show_question(self):
print(question)
def store_resp**e(self, new_resp**e):
self.resp**es.append(new_resp**e)
def show_results(self):
print("Survey results:")
for resp**e in resp**es:
print('- ' + resp**e)
language_survey.py
from survey import AnonymousSurvey
question = "What language did you first learn to speak?"
my_survey = AnonymousSurvey(question)
my_survey.show_question()
print("Enter 'q' at any time to quit.\n")
while True:
resp**e = input("Language: ")
if resp**e == 'q':
break
my_survey.store_resp**e(resp**e)
print("\nThank you to everyone who participated in the survey!")
my_survey.show_results()
运行出错:
File "C:/Users/robin/.PyCharm2018.1/config/scratches/language_survey.py", line 4, in <module>
my_survey.show_question()
File "C:\Users\robin\.PyCharm2018.1\config\scratches\survey.py", line 9, in show_question
print(question)
NameError: global name 'question' is not defined
Process finished with exit code 1
|
|