-1
class Pet(object):
    """
        Object that contains attributes relating to pets

        Methods:
        __init__: initializes a new object
        __str__: prints an object
        is_heavier: compares two pets' weights. Return True if self is heavier
        than second, otherwise returns False.
        is_older: compares two pets' ages. Returns true if self is older
        than second, otherwise returns False.
        Same_colour: compares two pets' colours. Returns True if colours match
        Returns False if Colours don't match.

        Attributes:
        species: str of type of pet IE "dog" or "giraffe"
        name: str listing the name of your pet IE "Joy" (She's a dog")
        weight: float the weight of the pet in killograms
        height: float the height of the pet in centimetres
        age: int the age of the pet in years.
    """
    def __init__(self, name, animal_type, age, weight, height):
        self.__name = name
        self.__animal_type = animal_type
        self.__age = age
        self.__heavier = weight
        self.__taller = height


    def set_name(self, name):
        self.__name = name

    def set_type(self, animal_type):
        self.__animal_type = animal_type

    def set_age(self, age):
        self.__age = age

    def get_name(self):
        return self.__name

    def get_animal_type(self):
        return self.__animal_type

    def get__age(self):
        return self.__age

    def get__heavier(self,heavier):
        return self.__weight

    def get__taller(self, taller):
        return self.__height

def main():
    name = input('What is the name of the pet: ')
    animal_type = input('What type of pet is it: ')
    age = int(input('How old is your pet: '))
    pets = Pet(name, animal_type, age)
    heavier = int(input('How much does your pet weight?: ')

    print('This will be added to the records.')
    print('Here is the data you entered: ')
    print('Pet Name: ', pets.get_name())
    print('Animal Type: ', pets.get_animal_type())
    print('Age: ', pets.get__age())
    print('Kg: ', pets.get__heavier())

main()

So This is supposed to be done by last Thursday, and I am STILL working on this assignment, and since it is quarantined so my teacher can't really help me with this work, and I kinda figure it out but it keeps giving me an error of the wrong spot of the code like the "print" is wrong or something like that. I think something is wrong with this code, and I can't figure out why or what is wrong with this code. Can you guys please please please help me with good explanations?

the Title won't let me make my own so I HAD to choose that one. NOT MY FAULT! :)

  • 1
    Does `pets = Pet(name, animal_type, age)` agree with `__init__(self, name, animal_type, age, weight, height)` required arguments? – jpf Apr 29 '20 at 01:34
  • What errors are you getting when you run your code? Do you get an exception? If so, show the full stack trace, it should identify the line the issue is happening on (though it does take some experience to interpret it). – Blckknght Apr 29 '20 at 01:52

2 Answers2

0
  1. you forgot to pass all argument to the Pet class when you initiated it
  2. get__heavier and get__taller used not existed variables

Below is the working copy program

class Pet(object):
    """
        Object that contains attributes relating to pets

        Methods:
        __init__: initializes a new object
        __str__: prints an object
        is_heavier: compares two pets' weights. Return True if self is heavier
        than second, otherwise returns False.
        is_older: compares two pets' ages. Returns true if self is older
        than second, otherwise returns False.
        Same_colour: compares two pets' colours. Returns True if colours match
        Returns False if Colours don't match.

        Attributes:
        species: str of type of pet IE "dog" or "giraffe"
        name: str listing the name of your pet IE "Joy" (She's a dog")
        weight: float the weight of the pet in killograms
        height: float the height of the pet in centimetres
        age: int the age of the pet in years.
    """

    def __init__(self, name, animal_type, age, weight, height):
        self.__name = name
        self.__animal_type = animal_type
        self.__age = age
        self.__heavier = weight
        self.__taller = height

    def set_name(self, name):
        self.__name = name

    def set_type(self, animal_type):
        self.__animal_type = animal_type

    def set_age(self, age):
        self.__age = age

    def get_name(self):
        return self.__name

    def get_animal_type(self):
        return self.__animal_type

    def get__age(self):
        return self.__age

    def get__heavier(self):
        return self.__heavier

    def get__taller(self):
        return self.__taller


def main():
    name = input('What is the name of the pet: ')
    animal_type = input('What type of pet is it: ')
    age = int(input('How old is your pet: '))
    weight = int(input('How much does your pet weight?: '))
    height = int(input('How much does your pet height?: '))
    pets = Pet(name, animal_type, age, weight, height)

    print('This will be added to the records.')
    print('Here is the data you entered: ')
    print('Pet Name: ', pets.get_name())
    print('Animal Type: ', pets.get_animal_type())
    print('Age: ', pets.get__age())
    print('Kg: ', pets.get__heavier())

main()
Jack Klimov
  • 378
  • 2
  • 10
0

I think error your generated on the basis of No or argument. if you observe your code

def __init__(self, name, animal_type, age, weight, height):
        self.__name = name
        self.__animal_type = animal_type
        self.__age = age
        self.__heavier = weight
        self.__taller = height

require total 5 argument while you passed only 3 of them

pets = Pet(name, animal_type, age)

correct format

pets = Pet(name, animal_type, age,weight,height)
Welcome_back
  • 1,245
  • 12
  • 18