-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathclass_methods.py
More file actions
54 lines (40 loc) · 1020 Bytes
/
class_methods.py
File metadata and controls
54 lines (40 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""class Cat:
def __init__(self):
self.color = ""
self.name = ""
self.weight = 0
def meow(self):
print("Meow!")
my_cat = Cat()
my_cat.color = "Brown"
my_cat.name = "Tank"
my_cat.weight = 10
print("My cats name is", my_cat.name)
my_cat.meow()
class Monster:
def __init__(self):
self.name = ""
self.health = 0
def decrease_health(self, amount):
self.health -= amount
if 0 >= self.health:
print("The monster is dead.")
monster1 = Monster()
monster1.name = "Omnom"
monster1.health = 30
print("The monster is", monster1.name)
monster1.decrease_health(31)
class Monster:
def __init__(self, health, name):
self.name = name
self.health = health
def decrease_health(self, amount):
self.health -= amount
if 0 >= self.health:
print("The monster is dead.")
class Star:
def __init__(self):
print("A star is born!")
star1 = Star()
star2 = Star()
star3 = Star()"""