Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # First Steps in OOP - Lab
- # https://pastebin.com/u/GeorgiLukanov87
- # 01. Rhombus of Stars
- # 02. Scope Mess
- # 03. Class Book
- # 04. Car
- # 05. Music
- ------------------------------------------------------------------------------------------------
- # 01. Rhombus of Stars
- def print_rhombus_func(n):
- for i in range(n):
- print((n - 1 - i) * " " + (i + 1) * '* ')
- for i in range(n - 1):
- print((i+1) * " " + (n-1-i) * "* ")
- n = int(input())
- print_rhombus_func(n)
- ------------------------------------------------------------------------------------------------
- # 02. Scope Mess
- x = 'global'
- def outer():
- global x
- x = 'local'
- def inner():
- global x
- x = 'nonlocal'
- print('inner:', x)
- def change_global():
- global x
- x = "global: changed!"
- print("outer:", x)
- inner()
- print("outer:", x)
- change_global()
- print(x)
- outer()
- print(x)
- ------------------------------------------------------------------------------------------------
- # 03. Class Book
- class Book:
- def __init__(self, name, author, pages):
- self.name = name
- self.author = author
- self.pages = pages
- # 04. Car
- class Car:
- def __init__(self, name, model, engine):
- self.name = name
- self.model = model
- self.engine = engine
- def get_info(self):
- return f'This is {self.name} {self.model} with engine {self.engine}'
- ------------------------------------------------------------------------------------------------
- # 05. Music
- class Music:
- def __init__(self, title, artist, lyrics):
- self.title = title
- self.artist = artist
- self.lyrics = lyrics
- def print_info(self):
- return f'This is "{self.title}" from "{self.artist}"'
- def play(self):
- return self.lyrics
- ------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement