#Pet Class #by Robert Layton class Pet(object): #Attributes -- had to use "petType" because 'type' is a reserved word name="" petType="" age=0 #Methods def setName(self, text): self.name = text def setType(self, text): self.petType = text def setAge(self, num): self.age = num def getName(self): return self.name def getType(self): return self.petType def getAge(self): return self.age # Create and Set Pet Info myPet = Pet() #myPet.setName("Max") #myPet.setType("Dog") #myPet.setAge(7) myPet.setName(raw_input("Enter your pet's name\n")) myPet.setType(raw_input("What type of pet is it?\n")) myPet.setAge(raw_input("How old is it?\n")) # Print out Pet Info print '\n\nPET INFO ACCEPTED' print myPet.getName() print myPet.getType() print str(myPet.getAge())
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question