Poganu

Curs 3 Iulie

Jul 8th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.05 KB | None | 0 0
  1. class Data:
  2.     def __init__(self, z, l, a):
  3.         self.zi = z #proprietate
  4.         self.luna = l
  5.         self.an = a
  6.  
  7.     def __repr__(self):
  8.         return "(" + str(self.zi) + ", " + str(self.luna) + ", " + str(self.an) + ")"
  9.  
  10.     def __eq__(self, bunica):
  11.         c1 = self.zi == bunica.zi # este o conditie: true sau false
  12.         c2 = self.luna == bunica.luna # tot conditie
  13.         c3 = self.an == bunica.an # conditie
  14.  
  15.         return c1 and c2 and c3
  16.  
  17.     def __lt__(self, scufita):
  18.         # __lt__ = less than
  19.         # __gt__ = greated than
  20.         # __le__ = less than and equal
  21.         # __ge__ = greated then and equal
  22.  
  23.         # facem sortarea datelor prin verificare de conditii
  24.         # intai incepem cu anul, apoi luna, apoi ziua
  25.         if self.an < scufita.an:
  26.             return True
  27.         elif self.an > scufita.an:
  28.             return False
  29.         elif self.luna < scufita.luna:
  30.             return True
  31.         elif self.luna > scufita.luna:
  32.             return False
  33.         elif self.zi < scufita.zi:
  34.             return True
  35.         elif self.zi > scufita.zi:
  36.             return False
  37.         else:
  38.             return False
  39.  
  40.     def __sub__(self, lupu):
  41.         q1 = (self.an - 1) * 365 + (self.luna - 1) * 30 + self.zi
  42.         q2 = (lupu.an - 1) * 365 + (lupu.luna - 1) * 30 + lupu.zi
  43.         dif = abs(q1 - q2)
  44.  
  45.         ani = int(dif // 365)
  46.         luni = int((dif % 365) // 30)
  47.         zile = int(dif % 365 % 30)
  48.         vanatorul = Data(zile, luni, ani)
  49.         return vanatorul
  50.  
  51. class Locatie:
  52.     def __init__(self, x, y):
  53.         self.__x = x
  54.         self.__y = y
  55.  
  56.     def __repr__(self):
  57.         print("X: ", self.__x)
  58.         print("Y: ", self.__y)
  59.  
  60.     def setLocatie(self, x, y):
  61.         self.__x = x
  62.         self.__y = y
  63.  
  64.     def getLocatieX(self):
  65.         return self.__x
  66.  
  67.     def getLocatieY(self):
  68.         return self.__y
  69.  
  70.  
  71. class ObiectivTuristic:
  72.     def __init__(self, nume, locatie, pret=10):
  73.         #self.__anInfiintare = 1900
  74.         self.numeObiectiv = nume
  75.         self.locatieObiectiv = locatie
  76.         self.pretLocatie = pret
  77.  
  78.  
  79.     def __new__(cls):
  80.         an = int(input("Introduceti anul: "))
  81.         nume = str(input("Introduceti numele: "))
  82.         x = int(input("Introduceti locatie x: "))
  83.         y = int(input("Introduceti locatie y: "))
  84.         pret = int(input("Introduceti pretul: "))
  85.  
  86.         obiect = super().__new__(cls)
  87.         #obiect = cls.__init__(nume, Locatie(x,y), pret)
  88.         obiect.anInfiintare = an
  89.         obiect.numeObiectiv = nume
  90.         obiect.locatieObiectiv = Locatie(x, y)
  91.         obiect.pretLocatie = pret
  92.         return obiect
  93.  
  94.     def __repr__(self):
  95.         return "An infiintare: " #+ self.__anInfiintare
  96.  
  97.     def setAnInfiintare(self, an):
  98.         #self.__anInfiintare = an
  99.         pass
  100.  
  101.     def setNumeObiectiv(self, nume):
  102.         self.numeObiectiv = nume
  103.  
  104.     def setLocatieObiectiv(self, locatie):
  105.         self.locatieObiectiv = locatie
  106.  
  107.     def setPretIntrare(self, pret):
  108.         self.pretLocatie = pret
  109.  
  110.     def getAnInfiintare(self):
  111.         pass
  112.         #return self.anInfiintare
  113.  
  114.     def getNumeObiectiv(self):
  115.         return self.numeObiectiv
  116.  
  117.     def getLocatieObiectiv(self):
  118.         return self.locatieObiectiv
  119.  
  120.     def getPretIntrare(self):
  121.         return self.pretLocatie
  122.  
  123.  
  124. class TraseuTuristic:
  125.     def __init__(self, dataInceput, dataEnd, combustibil):
  126.         self.__obiectiv = []
  127.         self.__dataInceput = dataInceput
  128.         self.__dataEnd = dataEnd
  129.         self.__combustibil = combustibil
  130.  
  131.     def __repr__(self):
  132.  
  133.         for i in len(self.__obiectiv):
  134.             print("Obiectiv: ", self.__obiectiv[i])
  135.  
  136.  
  137.  
  138. print("-------------")
  139. locatie1 = Locatie(122, 15)
  140. locatiePrislop = Locatie(5,5)
  141. locatieArsenieBoca = Locatie(40, 40)
  142. #obiectiv1 = ObiectivTuristic( "Eiffel", locatie1)
  143. #obiectiv2 = ObiectivTuristic( "Parlament", locatiePrislop, 15)
  144. obiectiv3 = ObiectivTuristic()
  145.  
  146. #print(obiectiv1)
  147. #print(obiectiv2)
  148. print(obiectiv3)
  149. #a = obiectiv3.getAnInfiintare()
  150. #print(int(a))
Add Comment
Please, Sign In to add comment