Skip to content

Commit cdf58e3

Browse files
committed
Added First Steps in OOP - Lab
1 parent f0ac069 commit cdf58e3

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

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

Whitespace-only changes.
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)
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)
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)
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())
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

+3-2
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> |

0 commit comments

Comments
 (0)