i just started learning python and this is my issue, i am very new to python - i have two python files all in the same folder..
1. question.py
class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
def chkQuestion(self):
if self.answer != "":
return True
2. quiz.py
questions_prompts = [
"what color are apples? \n (a) red \n(b) green \n(c) orange",
"what color are bananas? \n (a) Teal \n(b) Magenta \n(c) Yellow",
"what color are strawberries? \n (a) yellow \n(b) red \n(c) blue"
]
questions = []
answers = "bcd"
for i in range(3):
pos = int(i)-1
print(i)
questions.append(Question(questions_prompts[pos], answers[pos]))
print(questions[0].prompt)
when i print the questions list - it shows me all the questions added to the list as expected, but when i try to print out the prompt property of the first question (questions[0]) it gives this error
AttributeError: 'str' object has no attribute 'prompt'
pls what am i doing wrong, how do i push an object to a list and read the properties as expected. the tutorial created new question objects and passed the values manually, but i got curious what if i had 300+ questions, i cant do that manually, so i created the loop and i'm stuck.
answers[pos]?questionsnot initialized? 2. Why are you indexingquestions_promptsandanswerswithposwhich takes the values -1, 0, 1 instead ofiwhich takes the values 0, 1, 2? 3. What isanswers?