Advertisement
trds

Untitled

Mar 9th, 2021
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. from enum import Enum
  2. class Combustibil(Enum):
  3.     BENZINA=1
  4.     MOTORINA=2
  5.     GPL=3
  6.     ELECTRIC=4
  7.  
  8. class Masina (object):
  9.     def __init__(self,nr,c):
  10.         self.__nrInmatriculare=nr
  11.         self.__combustibil=c
  12.         self.__link= None
  13.  
  14.     def getnrInamtriculare(self):
  15.         return self.__nrInmatriculare
  16.     def getCombustibil(self):
  17.         return self.__combustibil
  18.     def getLink(self):
  19.         return self.__link
  20.     def setnrInamtriculare(self,newNr):
  21.         self.__nrInmatriculare=newNr
  22.     def setLink(self,newLink):
  23.         self.__link=newLink
  24.  
  25.     def __repr__(self):
  26.         return " Nr Inmatriculare :{} combustibil :{}".format(self.__nrInmatriculare,self.__combustibil)
  27.  
  28. m1=Masina("TM11ABC",Combustibil.BENZINA)
  29. m2=Masina("SV22AAA",Combustibil.GPL)
  30. print(m1)
  31. print(m2)
  32.  
  33. class Lista:
  34.     def __init__(self):
  35.         self.__radacina=None
  36.  
  37.     def adauga(self,masina):
  38.         if self.__radacina==None:
  39.             self.__radacina=masina
  40.         else:
  41.             masina.setLink(self.__radacina)
  42.             self.__radacina=masina
  43.  
  44.     def __repr__(self):
  45.         x=self.__radacina
  46.         while x!=None:
  47.             s=" "
  48.             s=s+str(x)
  49.             x=x.getLink()
  50.         return x
  51.  
  52.  
  53.  
  54.  
  55.  
  56. l=Lista()
  57. l.adauga(m1)
  58. l.adauga(m2)
  59. print(l)
  60. l.cautare(m1)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement