Test/Class
Verfasst: Montag 13. Mai 2019, 12:56
Hi brauche dringend eure hilfe und zwar komme ich nicht mehr weiter
Hier erstelle ich eine class die ich testen möchte
Hier weise ich ihr die werte hin zu und versuche sie ausführen aber es klappt nicht was ich garnicht verstehe Dies gibt er mir raus er eingeblich hätte question keine definition
Ich führe dies über die IDEL aus
Ich hoffe ihr könnt mir helfen
mfg fakhro
Hier erstelle ich eine class die ich testen möchte
Code: Alles auswählen
class AnonymousSurvey():
"""Collect anonymous ansers to a survey question."""
def __init__(self, question):
"""Store a question, and prepare to store responses."""
self.question = question
self.responses = []
def show_question(self):
"""Show the survey question"""
print(question)
def store_response(self, new_response):
"""Store a single response to the survey."""
self.responses.append(new_response)
def show_result(self):
"""Show all the responses that have been given."""
print("Survey Results:")
for response in responses:
print('- ' + response)
Code: Alles auswählen
from survey import AnonymousSurvey
# Define a question, and make a survey.
question = "What language did you first learn to speak?"
my_survey = AnonymousSurvey(question)
# Show the question, and store responses to the question.
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_respons(response)
# Show the survey results.
print("\nThank you to everyone who participated in the survey !")
Code: Alles auswählen
Traceback (most recent call last):
File "C:\Users\mojo\AppData\Local\Programs\Python\Python37-32\language_survey.py", line 8, in <module>
my_survey.show_question()
File "C:\Users\mojo\AppData\Local\Programs\Python\Python37-32\survey.py", line 11, in show_question
print(question)
NameError: name 'question' is not defined
Ich hoffe ihr könnt mir helfen
mfg fakhro