Aucune description

survey.py 708B

12345678910111213141516171819202122
  1. class AnonymousSurvey():
  2. """Collect anonymous answers to a survey question."""
  3. def __init__(self, question):
  4. """Store a question, and prepare to store responses."""
  5. self.question = question
  6. self.responses = []
  7. def show_question(self):
  8. """Show the survey question."""
  9. print(self.question)
  10. def store_response(self, new_response):
  11. """Store a single response to the survey."""
  12. self.responses.append(new_response)
  13. def show_results(self):
  14. """Show all the responses that have been given."""
  15. print("Survey results:")
  16. for response in self.responses:
  17. print('- ' + response)