Skip to content

Commit ac8e5d9

Browse files
committed
Created Python tutorials 29-34
1 parent f61033c commit ac8e5d9

6 files changed

Lines changed: 93 additions & 0 deletions

File tree

Python/29_python.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Enemy:
2+
life = 3
3+
4+
def attack(self):
5+
print("ouch!")
6+
self.life -=1
7+
8+
def checkLife(self):
9+
if self.life <= 0:
10+
print("I am dead")
11+
else:
12+
print(str(self.life) + " life left")
13+
14+
enemy1 = Enemy()
15+
enemy2 = Enemy()
16+
17+
enemy1.attack()
18+
enemy1.attack()
19+
enemy1.checkLife()
20+
enemy2.checkLife()

Python/30_python.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Enemy:
2+
def __init__(self, x):
3+
self.energy = x
4+
5+
def get_energy(self):
6+
print(self.energy)
7+
8+
jason = Enemy(5)
9+
sandy = Enemy(18)
10+
11+
jason.get_energy()
12+
sandy.get_energy()

Python/31_python.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Girl:
2+
3+
gender = 'female'
4+
5+
def __init__(self, name):
6+
self.name = name
7+
8+
r = Girl('Rachel')
9+
s = Girl('Stanky')
10+
print(r.gender)
11+
print(s.gender)
12+
print(r.name)
13+
print(s.name)

Python/32_python.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Parent:
2+
3+
def print_last_name(self):
4+
print('Roberts')
5+
6+
7+
class Child(Parent):
8+
9+
def print_first_name(self):
10+
print('Bucky')
11+
12+
def print_last_name(self):
13+
print('Snitzleberg')
14+
15+
bucky = Child()
16+
bucky.print_first_name()
17+
bucky.print_last_name()

Python/33_python.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Mario():
2+
3+
def move(self):
4+
print('I am moving!')
5+
6+
7+
class Shroom():
8+
9+
def eat_shroom(self):
10+
print('Now I am big!')
11+
12+
13+
class BigMario(Mario, Shroom):
14+
pass
15+
16+
bm = BigMario()
17+
bm.move()
18+
bm.eat_shroom()

Python/34_python.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import threading
2+
3+
4+
5+
class BuckysMessenger(threading.Thread):
6+
def run(self):
7+
for _ in range(10):
8+
print(threading.currentThread().getName())
9+
10+
x = BuckysMessenger(name='Send out messages')
11+
y = BuckysMessenger(name='Receive messages')
12+
x.start()
13+
y.start()

0 commit comments

Comments
 (0)