trds

Untitled

Jan 23rd, 2021
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. class punct:
  5.     def __init__(self, xx, yy):
  6.         self.__xx = xx
  7.         self.__yy = yy
  8.  
  9.     def __repr__(self):
  10.         return 'Punctul a este {} si punctul b este{}'.format(self.xx, self.yy)
  11.  
  12.     def __eq__(self, other):
  13.         if self.__xx == other.__xx and self.__yy == other.__yy:
  14.             return False
  15.         else:
  16.             return True
  17.  
  18.     def distanta(self, other):
  19.         dis = math.sqrt((self.__xx - other.__xx) ** 2 + (self.__xx - other.__yy) ** 2)
  20.         return dis
  21.  
  22.  
  23. class segment:
  24.     def __init__(self, a, b):
  25.         self.__a = a
  26.         self.__b = b
  27.  
  28.     def __repr__(self):
  29.         return 'Segmentul a are: {} iar segmentul b are: {}'.format(self.__a, self.__b)
  30.  
  31.     def intersectie(self, other):
  32.         pass
  33.  
  34.  
  35. p1 = punct(2, 3)
  36. p2 = punct(3, 5)
  37.  
  38. D = p1.distanta(p2)
  39. print(D)
  40.  
  41. class Station:
  42.  
  43.     def __init__(self,n,c,x,y):
  44.         self.nume=n
  45.         self.cod=c
  46.         self.x=x
  47.         self.y=y
  48.  
  49.     def __repr__(self):
  50.         return 'Sunteti in statia {}'.format(self.nume)
  51.  
  52.     @staticmethod
  53.     def getStations():
  54.         listaStatie=[]
  55.         fisier=open ("stationCode.txt","r")
  56.         # r = read, w = write , a = append
  57.  
  58.         for line in fisier:
  59.             pSpatiu = line.index(" ")
  60.             cod = line[ :pSpatiu]
  61.             denumire = line[pSpatiu+1:]
  62.             statie=Station(denumire,cod,None,None)
  63.             listaStatie.append(statie)
  64.  
  65.         listaCoordonate=[]
  66.         fisier=open("stationCord.txt","r")
  67.  
  68.         for line in fisier:
  69.             pSpatiu = line.index(" ")
  70.             pSpatiu2 = line.index (" ",pSpatiu+1)
  71.             cod = line [ :pSpatiu]
  72.             x = line[pSpatiu+1:pSpatiu2]
  73.             y = line[pSpatiu2:]
  74.             statie=Station
  75.             listaCoordonate.append(statie)
  76.             print(cod, end =" ")
  77.             print(x, end=" ")
  78.             print(y, end=" ")
  79.  
  80.  
  81. Station.getStations()
  82. # apel de functie statica
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment