Advertisement
trds

16decembrie2020

Dec 17th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. class Locomotiva:
  2.     def __init__ (self,p):
  3.         #constructorul locomotivei
  4.         #self este nr sub care a fost inregistrata locomotiva in memoria ram
  5.         self.putereLocomotiva = p
  6.     def __repr__(self):
  7.         return "Locmotiva de putere {}".format(self.putereLocomotiva)
  8. locomotivaluiRadu = Locomotiva (323)
  9. x = 3
  10. print (locomotivaluiRadu)
  11. print (x)
  12.  
  13. class VagonCalatori:
  14.     def __init__(self,nrMaxp,nrEfp):
  15.         self.nrMaximPasageri = nrMaxp
  16.         self.nrEfectivPasageri = nrEfp
  17.         #atribute(nrMaximPasageri si NrEfecticPasageri)
  18.         #parametri(neMaxp si nrEfp)
  19.     def __repr__(self):
  20.         return "Vagon calatori {}/ {} pasageri.".format(self.nrMaximPasageri ,self.nrEfectivPasageri)
  21.     def greutateVagon(self):
  22.         masaPopulatie = 80 * self.nrEfectivPasageri
  23.         masaTotala = 55 + masaPopulatie/1000
  24.         #masaPopulatie si masaTotala sunt variabile locale
  25.         return masaTotala
  26.     def venit(self, distanta):
  27.         incasareCalatori = 50 * self.nrEfectivPasageri
  28.         incasareTotala = (incasareCalatori * distanta) / 100
  29.         return incasareTotala
  30. VagonBianca = VagonCalatori (80, 23)
  31. VagonAndrei = VagonCalatori (80, 45)
  32.  
  33. class VagonMarfa:
  34.     def __init__ (self, tMax, vMax, Tip):
  35.         self.tonajEfectiv = tMax
  36.         self.volumMaxim = vMax
  37.         self.tip = Tip
  38.     def __repr__(self):
  39.         return "Vagon marfa {} / {} tonaj, volum.".format(self.tonajEfectiv, self.volumMaxim)
  40.     def greutate(self):
  41.         return 55 + self.tonajEfectiv
  42.        
  43. print (VagonBianca)
  44. print (VagonAndrei)
  45. print (VagonAndrei.greutateVagon())
  46. #prin greutate apelez functia de greutate asupra obiectului vagonAndrei
  47. #la apelarea unei functii NU se pune SELF
  48. print (VagonBianca.venit(480))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement