Question
Hello, I have a Python project to create a class... my code is below, though it's not running? Any help or advice woud be greatly
Hello, I have a Python project to create a "class"... my code is below, though it's not running? Any help or advice woud be greatly aprecciated with a thumbs up. Code is:
class Pet: #initialising the variables def __init__(self, name, aType, age): self.__name = name self.__animal_type = aType self.__age = age #method to assigns a value to the __name field def set_name(self, petName): __name = petName #method to assigns a value to the __animal_type field. def set_animal_type(self, petAType): __animal_type = petAType #method assigns a value to the __age field. def set_age(self, petAge): __age = petAge #method to get the value from the __name field def get_name(self): return __name #method to get the value from the __animal_type field. def get_type(self): return __animal_type #method to get the value from the __age field. def get_age(self): return __age
#main function def main(): #initialize the set with elements p = Pet("","",0) # Ask the user to enter the details of the pet name = input("Enter the name of your pet: ") p.set_name(name) a_type = input("Enter the type of your pet: ") p.set_animal_type(a_type) age = input("Enter the type of your pet: ") p.set_age(age) #display details of the pet print("Your pet name is ", p.get_name) print("Your pet type is ", p.get_type) print("Your pet age is ", p.get_age) main()
input('Press enter to exit.')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started