This commit is contained in:
2025-12-19 09:33:17 +01:00
parent 046667b27c
commit 2e5ed5bdf4

View File

@@ -1,17 +1,29 @@
class Computer:
def __init__(self):
def __init__(self, info: str, typ: str):
print("Startujemy...")
# definicja właściwości obiektów tej lasy
self.procesor = "CPU at start"
self.speed = "5 GHz"
self.cpu_speed = 5000
self.informacja = info
self.typ = typ
def __str__(self):
return f"To jest {id(self)=}"
def informacje(self):
if self.cpu_speed < 3000:
text = "- to jest wolny komputer"
else:
text = "- to jest szybki komputer"
return f"Info: {self.informacja} / {text}"
komputer1 = Computer()
komputer2 = Computer()
# TypeError:
# Computer.__init__()
# missing 1 required positional argument:
# 'info'
komputer1 = Computer("Komputer z lat 90tych", "XT", 1200)
komputer2 = Computer("Inna informacja", "AT")
print(komputer1)
print('-------------------')
@@ -30,4 +42,11 @@ print('-------------------')
komputer1.nowe_property = "Jakaś tam"
print(dir(komputer1))
print(dir(komputer2))
print('-------------------')
print('-------------------')
# print(komputer1.informacje)
# <bound method Computer.informacje
# of <__main__.Computer object
# at 0x7d072baa3860>>
print(komputer1.informacje())