Skip to content

Commit 0e6b383

Browse files
authored
Added First Steps in OOP - Lab (#41)
2 parents 55bcee6 + a74479b commit 0e6b383

File tree

8 files changed

+91
-3
lines changed

8 files changed

+91
-3
lines changed

OOP/1.First Steps in OOP/# TODO.txt

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def rhombus_stars(number):
2+
for row in range(number * 2 - 1):
3+
spaces = abs(number - row - 1)
4+
stars = number - spaces
5+
print(' ' * spaces + '* ' * stars)
6+
7+
8+
num = int(input())
9+
rhombus_stars(num)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
x = "global"
2+
3+
4+
def outer():
5+
x = "local"
6+
7+
def inner():
8+
nonlocal x
9+
x = "nonlocal"
10+
print("inner:", x)
11+
12+
def change_global():
13+
global x
14+
x = "global: changed!"
15+
16+
print("outer:", x)
17+
inner()
18+
print("outer:", x)
19+
change_global()
20+
21+
22+
print(x)
23+
outer()
24+
print(x)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Book:
2+
3+
def __init__(self, name, author, pages):
4+
self.name = name
5+
self.author = author
6+
self.pages = pages
7+
8+
def name(self):
9+
return self.name
10+
11+
def author(self):
12+
return self.author
13+
14+
def pages(self):
15+
return self.pages
16+
17+
18+
''' TEST '''
19+
# book = Book("My Book", "Me", 200)
20+
# print(book.name)
21+
# print(book.author)
22+
# print(book.pages)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Car:
2+
3+
def __init__(self, name, model, engine):
4+
self.name = name
5+
self.model = model
6+
self.engine = engine
7+
8+
def get_info(self):
9+
return f"This is {self.name} {self.model} with engine {self.engine}"
10+
11+
12+
''' TEST '''
13+
# car = Car("Kia", "Rio", "1.3L B3 I4")
14+
# print(car.get_info())
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Music:
2+
3+
def __init__(self, title, artist, lyrics):
4+
self.title = title
5+
self.artist = artist
6+
self.lyrics = lyrics
7+
8+
def print_info(self):
9+
return f"This is \"{self.title}\" from \"{self.artist}\""
10+
11+
def play(self):
12+
return self.lyrics
13+
14+
15+
''' TESTS '''
16+
# song = Music("Title", "Artist", "Lyrics")
17+
# print(song.print_info())
18+
# print(song.play())

OOP/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| Python Object Oriented Programming |
22
| ---------------- |
3-
| Content Cell |
4-
| Content Cell |
3+
| <a href="1.First Steps in OOP">First Steps in OOP</a> |
4+
| ------------------------ |
5+
| <a href="1.First Steps in OOP/First Steps in OOP - Lab">First Steps in OOP</a> |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Course Exercise Lecturer - **[Diyan Kalaydzhiev](https://github.com/DiyanKalaydz
88
| Python Advanced | Python OOP |
99
| --------------- | ---------- |
1010
| <a href="Advanced">Advanced</a> | <a href="OOP">Object Oriented Programming</a> |
11-
| <a href="Advanced/1.Stacks, Queues, Tuples and Sets">Stacks, Queues, Tuples and Sets</a> | First Steps in OOP |
11+
| <a href="Advanced/1.Stacks, Queues, Tuples and Sets">Stacks, Queues, Tuples and Sets</a> | <a href="OOP/1.First Steps in OOP">First Steps in OOP</a> |
1212
| <a href="Advanced/2.Multidimensional Lists">Multidimensional Lists (AKA matrix)</a> | Classes and Objects |
1313
| <a href="Advanced/3.Functions Advanced">Functions Advanced</a> | Inheritance |
1414
| <a href="Advanced/4.Error Handling">Error Handling</a> | Encapsulation |

0 commit comments

Comments
 (0)