Files
2025_12_15_python/dzien_05/klasy_03_tl copy.py
2025-12-19 10:49:45 +01:00

51 lines
1.6 KiB
Python

from random import randint, choice
typy = ("XT8", "IBM PS/2", "AT206", "AT386", "AT386DX",
"Fijitsu", "Dell", "DEC", "Compaq",
"VAX OpemVMS", "IBM VM/360", "Z Series")
komputery = []
class Computer:
def __init__(self, info: str, typ: str, speed: int):
print("Startujemy...")
# definicja właściwości obiektów tej lasy
self.procesor = "CPU at start"
self.speed = "5 GHz"
self.cpu_speed = speed
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}"
for _ in range(50):
c_typ = choice(typy)
c_info = f"informacja o -> {c_typ}"
c_speed = randint(600, 6000)
comp = Computer(c_info, c_typ, c_speed)
komputery.append(comp)
print(komputery)
# [
# <__main__.Computer object at 0x76a3dcdff980>,
# <__main__.Computer object at 0x76a3dcdff9e0>,
# <__main__.Computer object at 0x76a3dc32d3a0>,
# <__main__.Computer object at 0x76a3dc340e00>,
# <__main__.Computer object at 0x76a3dc3400e0>
#]
for kazdy in komputery:
print(kazdy.informacje())
# Info: informacja o -> AT386DX / - to jest szybki komputer
# Info: informacja o -> XT8 / - to jest szybki komputer
# Info: informacja o -> IBM VM/360 / - to jest wolny komputer
# Info: informacja o -> AT386 / - to jest szybki komputer
# Info: informacja o -> DEC / - to jest wolny komputer