Açıklama Yok

dog.py 794B

12345678910111213141516171819202122232425262728
  1. class Dog():
  2. """A simple attempt to model a dog."""
  3. def __init__(self, name, age):
  4. """Initialize name and age attributes."""
  5. self.name = name
  6. self.age = age
  7. def sit(self):
  8. """Simulate a dog sitting in response to a command."""
  9. print(self.name.title() + " is now sitting.")
  10. def roll_over(self):
  11. """Simulate rolling over in response to a command."""
  12. print(self.name.title() + " rolled over!")
  13. my_dog = Dog('willie', 6)
  14. your_dog = Dog('lucy', 3)
  15. print("My dog's name is " + my_dog.name.title() + ".")
  16. print("My dog is " + str(my_dog.age) + " years old.")
  17. my_dog.sit()
  18. print("\nMy dog's name is " + your_dog.name.title() + ".")
  19. print("My dog is " + str(your_dog.age) + " years old.")
  20. your_dog.sit()