Python Forum
Help with Python Inheritance (One parent, two children)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Python Inheritance (One parent, two children)
#1
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 Smile
Reply


Messages In This Thread
Help with Python Inheritance (One parent, two children) - by b_salm - Jan-29-2020, 12:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print out the children index of the search tree? longmen 7 2,283 Apr-02-2022, 06:58 AM
Last Post: Yoriz
  Sorting Santa's List of Children sirox84 4 5,288 Feb-20-2017, 06:10 PM
Last Post: sirox84

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020