The class AnonymousSurvey () :
"" "collect anonymous questionnaire answers "" "
Def __init__ (self, question) :
"" "store a problem, and prepare for storing the answer "" "
The self. The question=question
Self. Responses=[]
Def show_question (self) :
"" "display questionnaire "" "
Print (question)
Def store_response (self, new_response) :
"" "store the survey paper "" "
Self. Responses. Append (new_response)
Def show_results (self) :
"" "according to the collected all the answer "" "
Print (" Survey results: ")
For the response in responses:
Print (' - '+ response)
Language_survey1. Py
The from survey1 import AnonymousSurvey
# define a problem, and create a said the investigation object of AnonymousSurvey
Question="What language did you first learn to speak?"
My_survey=AnonymousSurvey (question)
# show answers and store
My_survey. Show_question ()
Print (" Enter 'q' at any time to quit. \ n ")
While True:
The response=input (" Language: ")
If the response=='q:
Break
My_survey. Store_response (response)
# shows the results of the survey
Print (" \ nThank you to everyone who participated in the survey!" )
My_survey. Show_results ()
The error results
Traceback (the most recent call last) :
The File "C:/Users/15004/AppData/Local/designed/Python/Python38-32/language_survey1 py", line 8, the in & lt; module>
My_survey. Show_question ()
The File "C:/Users/15004/AppData/Local/designed/Python/Python38-32/survey1. Py", line 11, in show_question
Print (question)
NameError: name 'question' is not defined