Dec-22-2019, 12:21 PM
I'm trying to create a class to output a zipped list for other classes to use. This is the code:
Thanks for your help in advance
class Epworthquestions():
print("This is the Epworth sleepiness scale. ")
print("How likely are you to doze off or fall asleep in the following situations? 0 = never, 1= slight chance, 2= moderate chance, 3= high chance of dozing. ")
q1 = "Sitting and reading? "
q2 = "Watching TV? "
q3 = "Sitting, inactive in a public place? "
q4 = "As a passenger in a car for an hour without break? "
q5 = "Lying down to rest in the afternoon when circumstances permit? "
q6 = "Sitting and talking to someone? "
q7 = "Stiing quietly after a lunch without alcohol? "
q8 = "Driving in a car, while stopped for a few minutes in the traffic? "
questions = [q1,q2,q3,q4,q5,q6,q7,q8]
answer = []
def Epworth():
for question in Epworthquestions.questions:
while True:
a = input(question)
try:
ans = int(a)
except ValueError:
print("Please enter a number. ")
continue
if ans not in range(0,4):
print("Please enter a number between 0 and 4")
else:
Epworthquestions.answer.append(ans)
break
for q,a in zip(Epworthquestions.questions,Epworthquestions.answer):
c = [q,a]
return c
x = Epworthquestions.Epworth()
print(x)I needed the function Epworth() to output the whole list of questions and answers but all I get is the last question and answer:Output:This is the Epworth sleepiness scale.
How likely are you to doze off or fall asleep in the following situations? 0 = never, 1= slight chance, 2= moderate chance, 3= high chance of dozing.
Sitting and reading? 0
Watching TV? 0
Sitting, inactive in a public place? 0
As a passenger in a car for an hour without break? 0
Lying down to rest in the afternoon when circumstances permit? 0
Sitting and talking to someone? 0
Stiing quietly after a lunch without alcohol? 0
Driving in a car, while stopped for a few minutes in the traffic? 0
['Driving in a car, while stopped for a few minutes in the traffic? ', 0]What am I missing here?Thanks for your help in advance
