Skip to content

Instantly share code, notes, and snippets.

@drldcsta
Created April 5, 2020 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drldcsta/eeabc174d1f1c4439739cf6fb72cbcf5 to your computer and use it in GitHub Desktop.
Save drldcsta/eeabc174d1f1c4439739cf6fb72cbcf5 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
class Animal():
def __init__(self,name,species,sound,age):
self.name = name
self.species = species
self.sound = sound
self.age = age
def make_sound(self):
print(self.sound)
def intro_self(self):
print(f"Hello I am {self.name}, I am a {self.species}, and I go {self.sound}, and I am {self.age} years old ")
def has_birthday(self):
self.age = self.age + 1
# # print(f"{cat.species}")
# cat.make_sound()
cat = Animal("Bartelby", "Cat", "Meow",5)
cat.intro_self()
cat.has_birthday()
cat.intro_self()
# dog =Animal("Salt", "Dog", "Woof")
# dog.make_sound()
# dog.intro_self()
# dog = Animal("Loki", "Dog", "Bow Wow Wow, Yippie-o, Yippie-ay")
#dog.make_sound()
# dog.intro_self()
# class Rectangle():
# def __init__(self,x_len,y_len):
# self.x_len = x_len
# self.y_len = y_len
# def print_area(self):
# print(f"the area of this rectangle is {self.x_len * self.y_len}")
# smol_rect = Rectangle(3,2)
# smol_rect.print_area()
# huuge_rect = Rectangle(69,68)
# huuge_rect.print_area()
# total_length = smol_rect.x_len + huuge_rect.x_len
# print(f"{total_length}")
# class Square(Rectangle):
# def __init__(self,side):
# super().__init__(side,side)
# smol_sqr = Square(5)
# smol_sqr.print_area()
# huuge_sqr = Square(69)
# huuge_sqr.print_area()
class Player():
def __init__(self,name,health,mp):
self.name = name
self.health = health
self.mp = mp
def take_damage(self,damage):
self.health = self.health - damage
print(f"{self.name} took {damage} damage! Their health is now {self.health}")
def restore_health(self):
self.health = self.health + 15
self.mp = self.mp - 5
print(f"{self.name} used a potion for 5 mana. Their health is now {self.health}")
def print_stats(self):
print(f"{self.name} has {self.health} health and {self.mp} mana")
drl = Player("drl",100,50)
drl.take_damage(5)
drl.restore_health()
drl.print_stats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment