Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Created February 22, 2024 22:47
Show Gist options
  • Save srkiNZ84/52257a3328f6bf27f1093ae411a8d561 to your computer and use it in GitHub Desktop.
Save srkiNZ84/52257a3328f6bf27f1093ae411a8d561 to your computer and use it in GitHub Desktop.
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
pass
def bark(self):
print("bark bark!")
def doginfo(self):
print(self.name + " is " + str(self.age) + " year(s) old.")
def birthday(self):
self.age += 1
def set_buddy(self, buddy):
self.buddy = buddy
buddy.buddy = self
ozzy = Dog("Ozzy", 2)
skippy = Dog("Skippy", 12)
filou = Dog("Filou", 8)
ozzy.doginfo()
skippy.doginfo()
filou.doginfo()
ozzy.age = 3
ozzy.doginfo()
ozzy.birthday()
ozzy.doginfo()
ozzy.bark()
ozzy.set_buddy(filou)
print(ozzy.buddy.name)
print(ozzy.buddy.age)
print(filou.buddy.name)
print(filou.buddy.age)
ozzy.buddy.doginfo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment