Facebook
From Obese Wolf, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 226
  1. class Ksztalty:
  2. #definicja konstruktora
  3.     def __init__(self, x, y):
  4. #deklarujemy atrybuty
  5. #self wskazuje że chodzi o zmienne właśnie definiowanej klasy
  6.         self.x=x
  7.         self.y=y
  8.         self.opis = "To będzie klasa dla ogólnych kształtów"
  9.     def pole_prostokatu(self):
  10.         return self.x * self.y
  11.     def obwod(self):
  12.         return 2 * self.x + 2 * self.y
  13.     def dodaj_opis(self, text):
  14.         self.opis = text
  15.     def skalowanie(self, czynnik):
  16.         self.x = self.x * czynnik
  17.         self.x = self.y * czynnik
  18.  
  19. class Kwadrat(Ksztalty):
  20.     def __init__(self, x):
  21.         self.x =x
  22.         self.y=x
  23.     def __str__(self):
  24.         return 'Kwadrat o boku {}'.format(self.x)
  25.     def __add__(self):
  26.         return 'Suma bokow kwadratow: {} '.format(self.x*4)
  27.  
  28.  
  29. obiekt=Kwadrat(10)
  30. print(obiekt)
  31. obiekt=Kwadrat(10)
  32. print(obiekt.__add__())
  33.