Help with Python Inheritance (One parent, two children) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Help with Python Inheritance (One parent, two children) (/thread-24052.html) |
Help with Python Inheritance (One parent, two children) - b_salm - Jan-29-2020 class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer question_prompts = [ # array "What color are apples?\n(a) Red/Green\n(b) purple\n(c) Orange\n\n", "What color are bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n", "What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n" ] questions = [ Question(question_prompts[0], "a"), Question(question_prompts[1], "c"), Question(question_prompts[2], "b"), ] def run_test(questions): score = 0 for question in questions: answer = input(question.prompt) if answer == question.answer: score += 1 print("You got " + str(score) + "/" + str(len(questions)) + " correct") run_test(questions)This is my first time using Python. I have to make question_prompts, and questions the children. I have to make Question the parent. I've experimented in many ways trying to make each a separate class, I've spent a while trying to figure it out along with reading multiple articles. I am a beginner and would appreciate any help RE: Help with Python Inheritance (One parent, two children) - jefsummers - Jan-29-2020 Not sure what you are asking. Currently you have a class called Question, and questions is an array of objects of type Question. Can you clarify what you are wanting to do? RE: Help with Python Inheritance (One parent, two children) - b_salm - Jan-29-2020 Okay so I'm trying to call the children functions from the parent function. So questions and run_test are the children, and I'm trying to make it in a way where they are called from the parent function (question_prompts) RE: Help with Python Inheritance (One parent, two children) - buran - Jan-29-2020 I am afraid you are confused big time with concepts and terminology. Best would be to revisit your course material/study notes, etc. Inheritance, parent, child are concept and terms from object oriented programming (OOP). You have one class and no inheritance whatsoever question_prompts and questions are lists, not functions. The only function is run_test .Post your assignment verbatim or explain better what is required |