-3

Question: In a school, it is required to create a pick-up program in which each child is allowed to be picked up by one of his parents and at most one emergency contact. To do so, it is required to design 4 classes

  1. Dad Class: which includes Dad’s first name, last name, and phone number.
  2. Mon Class: which includes Dad’s first name, last name, and phone number.
  3. Emergency Contact class: Which includes the contact’s first name, last name, phone number and whether this contact is allowed to pick-up the child or not
  4. Child Class: Which will inherit all the previous data from the previous 3 classes, in addition to his name and grade. The Child class will also have a method called print_child_pickup_info to print a summary of the child name, along with his parents’ names, the emergency contact name, and whether is he allowed to pick up the child or not.

Here is my code. There is a problem with the line:

super().__init__(firstName, lastName, phone)
EmergencyContact.__init__(pickup)`

says that phone and pickup have an "unresolved reference"

Full code:

class Dad():
    def __init__(self, firstName, lastName, phone):
        self.firstName = firstName
        self.lastName = lastName
        self.phoneNumber = phone


class Mom():
    def __init__(self, firstName, lastName, phone):
        self.firstName = firstName
        self.lastName = lastName
        self.phoneNumber = phone

class EmergencyContact():
    def __init__(self, firstName, lastName, phone, pickup):
        self.firstName = firstName
        self.lastName = lastName
        self.phoneNumber = phone
        self.pickup = pickup

#Inheritance
class Child(Dad, Mom, EmergencyContact):
    def __ini__(self, firstName, lastName, grade):
        self.CfirstName = firstName
        self.ClastName = lastName
        self.Cgrade = grade
        super().__init__(firstName, lastName, phone)
        EmergencyContact.__init__(pickup)



    def print_child_pickup_info(self,D,M,EC):
        print(self.CfirstName,self.ClastName)
        print("Father Name:", D.firstName, D.lastName)
        print("Mother Name:", M.firstName, M.lastName)
        print("Emergency Contact Name:", EC.firstName, EC.lastName)
        print("Can pick:", EC.pickup)
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Ah, so what is not clear? You don't pass a `phone` or `pickup` argument to `Child`'s initializer. Which phone number do you expect it to pass to the superclass? – Selcuk Dec 08 '20 at 23:51
  • 2
    Your class hierarchy doesn't really make sense. Inheritance represents IS-A relationships. So you're saying that a Child is a Dad and it's also a Mom and it's also an EmergencyContact. That's not right. A child *has* a Dad and Mom, but you don't use inheritance for HAS-A relationships. – Barmar Dec 08 '20 at 23:56
  • There are various other issues as well (for example it must be `__init__`, not `__ini__`). I would suggest you to start with an introductory Python/OO tutorial before writing code. – Selcuk Dec 08 '20 at 23:57
  • So unresolved reference is probably because of that typo. – Barmar Dec 08 '20 at 23:58
  • @Barmar No, it's because there are no variables named `phone` or `pickup` in that method. – Selcuk Dec 08 '20 at 23:58
  • The proper hierarchy would be something like Person, Child(Person). Child should have attributes `mom`, `dad`, and `emergency_contact`. – Barmar Dec 09 '20 at 00:00
  • It is a really bad Class example given by your teacher ... Are you sure the Child class should inherit the others ? or just have them as attributes ? Which would make sense. Like you wrote, there will be plenty of problems ... and attributes with same names will be difficult to access .... very bad example for beginners. – Malo Dec 09 '20 at 00:06
  • You use 'phone' variable in the Child.__init__() without having defined it.... which you should do. And EmergencyContact. has not __init__(pickup) method with only one argument ... etc ... – Malo Dec 09 '20 at 00:08
  • Not this way. Can you chose to create a Person class ? and Child Class, Dad Class, and Mom Class can inherit the Person class ? that would be fine and logic. – Malo Dec 09 '20 at 00:10

1 Answers1

1

'phone' and 'pickup' have an "unresolved reference" because you have not defined them in the .init(...) method of Child class. But this is just the answer ... and your code seems to have some other issues ...

class Child(Dad, Mom, EmergencyContact):
    def __ini__(self, firstName, lastName, grade):
        self.CfirstName = firstName
        self.ClastName = lastName
        self.Cgrade = grade
        phone = '1234567890'
        pickup = True
        super().__init__(firstName, lastName, phone)
        EmergencyContact.__init__(pickup)
Malo
  • 1,233
  • 1
  • 8
  • 25