Advertisement
bruh1214

Untitled

Oct 20th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.66 KB | None | 0 0
  1. from datetime import datetime
  2. import datetime
  3.  
  4.  
  5. def creeaza_pachet(data_i, data_s, dest, pret):
  6. # functie care creeaza un pachet de calatorie cu data de inceput data_i de tip data, data de sfarsit de tip data,
  7. # dest o destinatie string si pret de tip float > 0
  8. # input: data_i = data de inceput - data
  9. # data_s = data de sfarsit - data
  10. # dest = destinatie - string
  11. # pret = pret - float > 0
  12. return {
  13. "data_i": data_i,
  14. "data_s": data_s,
  15. "dest": dest,
  16. "pret": pret
  17. }
  18.  
  19.  
  20. def get_data_i(pachet):
  21. # functie care returneaza data de inceput a pachetului pachet
  22. # input: pachet - un pachet
  23. # output: data - o data
  24. return pachet["data_i"]
  25.  
  26.  
  27. def get_data_s(pachet):
  28. # functie care returneaza data data de sfarsit a pachetului pachet
  29. # input: pachet - un pachet
  30. # output: data - o data
  31. return pachet["data_s"]
  32.  
  33.  
  34. def get_destinatie(pachet):
  35. # functie care returneaza destinatia string a pachetului pachet
  36. # input: pachet - un pachet
  37. # output: destinatia string a pachetului
  38. return pachet["dest"]
  39.  
  40.  
  41. def get_pret(pachet):
  42. # functie care returneaza pretul float a pachetului pachet
  43. # input: pachet - un pachet
  44. # output: pretul float > 0 al pachetului
  45. return pachet["pret"]
  46.  
  47.  
  48. def valideaza_pachet(pachet):
  49. # functie care valideaza daca un pachet pachet este introdus corect sau nu
  50. # input : pachet - pachet
  51. # output: -, daca pachetul a fost introdus corect
  52. # raises Exception cu mesajul
  53. # "date gresite!"
  54. # "destinatie gresita!"
  55. # "pret gresit!"
  56. err = ""
  57. if get_data_i(pachet) > get_data_s(pachet):
  58. err += "date gresite!\n"
  59. if get_destinatie(pachet) == " ":
  60. err += "destinatie gresita!\n"
  61. if get_pret(pachet) <= 0:
  62. err += "pret gresit!\n"
  63. if len(err) > 0:
  64. raise Exception(err)
  65.  
  66.  
  67. def egale_pret(p0, p1):
  68. return get_pret(p0) == get_pret(p1)
  69.  
  70.  
  71. def egale_dest(p0, p1):
  72. return get_destinatie(p0) == get_destinatie(p1)
  73.  
  74.  
  75. def egale_data_i(p0, p1):
  76. return get_data_i(p0) == get_data_i(p1)
  77.  
  78.  
  79. def egale_data_s(p0, p1):
  80. return get_data_s(p0) == get_data_s(p1)
  81.  
  82.  
  83. def adauga_pachet_in_lista(l, pachet):
  84. # functie care adauga un pachet intr-o lista
  85. # input: l - lista
  86. # pachet - pachet
  87. # output: l' - lista cu pachetul
  88. # raises Exception cu mesajul
  89. # "pachet cu aceleasi date introduse!\n"
  90. # daca aceleasi date au fost introduse din nou
  91. for _pachet in l:
  92. if egale_pret(_pachet, pachet) and egale_dest(_pachet, pachet) and egale_data_i(_pachet,
  93. pachet) and egale_data_s(
  94. _pachet, pachet):
  95. raise Exception("pachet cu aceleasi date introduse!\n")
  96. l.append(pachet)
  97.  
  98.  
  99. def remove_pret(pachet):
  100. nou_p = dict(pachet)
  101. del nou_p["pret"]
  102. return nou_p
  103.  
  104.  
  105. def remove_data_i(pachet):
  106. nou_p = dict(pachet)
  107. del nou_p["data_i"]
  108. return nou_p
  109.  
  110.  
  111. def remove_data_s(pachet):
  112. nou_p = dict(pachet)
  113. del nou_p["data_s"]
  114. return nou_p
  115.  
  116.  
  117. def remove_dest(pachet):
  118. nou_p = dict(pachet)
  119. del nou_p["dest"]
  120. return nou_p
  121.  
  122.  
  123. def srv_adauga_pachet_in_lista(l, data_i, data_s, dest, pret):
  124. # functie care creeaza un pachet si incearca sa il introduca in lista l
  125. # input: l - lista
  126. # pachet - pachet
  127. # output: -, daca totul e ok
  128. # raises Exception cu mesajele din functiile anterioare
  129. pachet = creeaza_pachet(data_i, data_s, dest, pret)
  130. valideaza_pachet(pachet)
  131. adauga_pachet_in_lista(l, pachet)
  132.  
  133.  
  134. def test_srv_adauga_pachet_in_lista():
  135. l = []
  136. assert (len(l) == 0)
  137. srv_adauga_pachet_in_lista(l, datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  138. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"), "Galati", 9000.1)
  139. assert (len(l) == 1)
  140. try:
  141. srv_adauga_pachet_in_lista(l, datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  142. datetime.datetime.strptime('22/08/2021', "%d/%m/%Y"), " ", 9000.1)
  143. assert False
  144. except Exception as ex:
  145. assert (str(ex) == "date gresite!\ndestinatie gresita!\n")
  146.  
  147.  
  148. def test_modifica_date():
  149. l = []
  150. assert len(l) == 0
  151. pachet = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  152. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  153. "Galati", 9000.1)
  154. adauga_pachet_in_lista(l, pachet)
  155. assert len(l) == 1
  156. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  157. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  158. "Galati", 9040.1)
  159. adauga_pachet_in_lista(l, pachet_2)
  160. assert len(l) == 2
  161. pass
  162.  
  163.  
  164. def test_adauga_pachet_in_lista():
  165. l = []
  166. assert (len(l) == 0)
  167. pachet = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  168. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  169. "Galati", 9000.1)
  170. adauga_pachet_in_lista(l, pachet)
  171. assert (len(l) == 1)
  172. assert (get_data_i(pachet) == get_data_i(l[0]))
  173. assert (get_data_s(pachet) == get_data_s(l[0]))
  174. assert (get_destinatie(pachet) == get_destinatie(l[0]))
  175. assert (abs(get_pret(pachet) - get_pret(l[0]) < 0.0001))
  176. alt_pachet = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  177. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"), "Galati", 9000.1)
  178. try:
  179. adauga_pachet_in_lista(l, alt_pachet)
  180. assert False
  181. except Exception as ex:
  182. assert (str(ex) == "pachet cu aceleasi date introduse!\n")
  183.  
  184.  
  185. def test_valideaza_pachet():
  186. pachet = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  187. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  188. "Galati", 9000.1)
  189. valideaza_pachet(pachet)
  190. pachet_gresit = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  191. datetime.datetime.strptime('22/08/2021', "%d/%m/%Y"), "Galati", 9000.1)
  192. try:
  193. valideaza_pachet(pachet_gresit)
  194. except Exception as ex:
  195. assert (str(ex) == "date gresite!\n")
  196. alt_pachet = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  197. datetime.datetime.strptime('22/08/2021', "%d/%m/%Y"), " ", -904)
  198. try:
  199. valideaza_pachet(alt_pachet)
  200. assert False
  201. except Exception as ex:
  202. assert (str(ex) == "date gresite!\ndestinatie gresita!\npret gresit!\n")
  203.  
  204.  
  205. def test_creeaza_pachet():
  206. data_i_string = '24/08/2021'
  207. data_i = datetime.datetime.strptime(data_i_string, "%d/%m/%Y")
  208. data_s_string = '26/08/2021'
  209. data_s = datetime.datetime.strptime(data_s_string, "%d/%m/%Y")
  210. dest = "Galati"
  211. pret = 9000.1
  212. pachet = creeaza_pachet(data_i, data_s, dest, pret)
  213. assert (get_data_i(pachet) == data_i)
  214. assert (get_data_s(pachet) == data_s)
  215. assert (get_destinatie(pachet) == dest)
  216. assert (abs(get_pret(pachet) - pret) < 0.0001)
  217.  
  218.  
  219. def test_numar_oferte():
  220. l = []
  221. pachet_1 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  222. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  223. "Galati", 9000.1)
  224. pachet_2 = creeaza_pachet(datetime.datetime.strptime('23/08/2021', "%d/%m/%Y"),
  225. datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  226. "Galati", 9200.1)
  227. pachet_3 = creeaza_pachet(datetime.datetime.strptime('19/08/2021', "%d/%m/%Y"),
  228. datetime.datetime.strptime('22/08/2021', "%d/%m/%Y"),
  229. "Galati", 90040.1)
  230. pachet_4 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  231. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  232. "Braila", 9020.1)
  233. adauga_pachet_in_lista(l, pachet_1)
  234. adauga_pachet_in_lista(l, pachet_2)
  235. adauga_pachet_in_lista(l, pachet_3)
  236. adauga_pachet_in_lista(l, pachet_4)
  237. nr_oferte = 0
  238. for _pachet in l:
  239. if get_destinatie(_pachet) == "Galati":
  240. nr_oferte += 1
  241. assert nr_oferte == 3
  242.  
  243.  
  244. def test_sterge_zile():
  245. l = []
  246. assert len(l) == 0
  247. pachet_1 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  248. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  249. "Galati", 9000.1)
  250. pachet_2 = creeaza_pachet(datetime.datetime.strptime('23/08/2021', "%d/%m/%Y"),
  251. datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  252. "Galati", 9200.1)
  253. pachet_3 = creeaza_pachet(datetime.datetime.strptime('19/08/2021', "%d/%m/%Y"),
  254. datetime.datetime.strptime('25/08/2021', "%d/%m/%Y"),
  255. "Galati", 90040.1)
  256. pachet_4 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  257. datetime.datetime.strptime('29/08/2021', "%d/%m/%Y"),
  258. "Braila", 9020.1)
  259. adauga_pachet_in_lista(l, pachet_1)
  260. adauga_pachet_in_lista(l, pachet_2)
  261. adauga_pachet_in_lista(l, pachet_3)
  262. adauga_pachet_in_lista(l, pachet_4)
  263. assert len(l) == 4
  264. sterge_zile(l, 3)
  265. assert len(l) == 2
  266.  
  267.  
  268. def test_medie_pret():
  269. l = []
  270. pachet_1 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  271. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  272. "Galati", 9000.1)
  273. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  274. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  275. "Galati", 9011)
  276. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  277. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  278. "Galati", 9211.2)
  279. adauga_pachet_in_lista(l, pachet_1)
  280. adauga_pachet_in_lista(l, pachet_2)
  281. adauga_pachet_in_lista(l, pachet_3)
  282. for _pachet in l:
  283. try:
  284. medie_pret(l, "Galati")
  285. except ZeroDivisionError:
  286. assert medie_pret(l, "Galati") == "Media pretului este ", 9074.1
  287.  
  288.  
  289. def test_sterge_pret():
  290. l = []
  291. assert len(l) == 0
  292. pachet_1 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  293. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  294. "Galati", 9000.1)
  295. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  296. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  297. "Galati", 9011)
  298. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  299. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  300. "Galati", 2211.2)
  301. adauga_pachet_in_lista(l, pachet_1)
  302. adauga_pachet_in_lista(l, pachet_2)
  303. adauga_pachet_in_lista(l, pachet_3)
  304. assert len(l) == 3
  305. sterge_pret(l, 5000)
  306. assert len(l) == 1
  307.  
  308.  
  309. def test_sterge_pachet_dest():
  310. l = []
  311. assert len(l) == 0
  312. pachet_1 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  313. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  314. "Galati", 9000.1)
  315. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  316. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  317. "Galati", 9011)
  318. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  319. datetime.datetime.strptime('26/08/2021', "%d/%m/%Y"),
  320. "Braila", 2211.2)
  321. adauga_pachet_in_lista(l, pachet_1)
  322. adauga_pachet_in_lista(l, pachet_2)
  323. adauga_pachet_in_lista(l, pachet_3)
  324. assert len(l) == 3
  325. sterge_pachet_dest(l, "Galati")
  326. assert len(l) == 1
  327.  
  328.  
  329. def test_verificare_sters_zile():
  330. l = []
  331. assert len(l) == 0
  332. pachet_1 = creeaza_pachet(datetime.datetime.strptime('4/08/2021', "%d/%m/%Y"),
  333. datetime.datetime.strptime('20/08/2021', "%d/%m/%Y"),
  334. "Galati", 9000.1)
  335. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  336. datetime.datetime.strptime('29/08/2021', "%d/%m/%Y"),
  337. "Galati", 9011)
  338. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  339. datetime.datetime.strptime('25/08/2021', "%d/%m/%Y"),
  340. "Braila", 2211.2)
  341. adauga_pachet_in_lista(l, pachet_1)
  342. adauga_pachet_in_lista(l, pachet_2)
  343. adauga_pachet_in_lista(l, pachet_3)
  344. assert len(l) == 3
  345. assert verificare_sters_zile(l,6) == True
  346.  
  347.  
  348. def test_verificare_sters_dest():
  349. l = []
  350. assert len(l) == 0
  351. pachet_1 = creeaza_pachet(datetime.datetime.strptime('4/08/2021', "%d/%m/%Y"),
  352. datetime.datetime.strptime('20/08/2021', "%d/%m/%Y"),
  353. "Galati", 9000.1)
  354. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  355. datetime.datetime.strptime('29/08/2021', "%d/%m/%Y"),
  356. "Galati", 9011)
  357. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  358. datetime.datetime.strptime('25/08/2021', "%d/%m/%Y"),
  359. "Braila", 2211.2)
  360. adauga_pachet_in_lista(l, pachet_1)
  361. adauga_pachet_in_lista(l, pachet_2)
  362. adauga_pachet_in_lista(l, pachet_3)
  363. assert len(l) == 3
  364. assert verificare_sters_dest(l, "Galati") == True
  365.  
  366.  
  367. def test_verificare_sters_luna():
  368. l = []
  369. assert len(l) == 0
  370. pachet_1 = creeaza_pachet(datetime.datetime.strptime('4/08/2021', "%d/%m/%Y"),
  371. datetime.datetime.strptime('20/08/2021', "%d/%m/%Y"),
  372. "Galati", 9000.1)
  373. pachet_2 = creeaza_pachet(datetime.datetime.strptime('24/08/2021', "%d/%m/%Y"),
  374. datetime.datetime.strptime('29/08/2021', "%d/%m/%Y"),
  375. "Galati", 9011)
  376. pachet_3 = creeaza_pachet(datetime.datetime.strptime('24/09/2021', "%d/%m/%Y"),
  377. datetime.datetime.strptime('25/09/2021', "%d/%m/%Y"),
  378. "Braila", 2211.2)
  379. adauga_pachet_in_lista(l, pachet_1)
  380. adauga_pachet_in_lista(l, pachet_2)
  381. adauga_pachet_in_lista(l, pachet_3)
  382. assert len(l) == 3
  383. assert verificare_sters_luna(l, 8) == True
  384.  
  385.  
  386. def run_teste():
  387. test_creeaza_pachet()
  388. test_valideaza_pachet()
  389. test_adauga_pachet_in_lista()
  390. test_srv_adauga_pachet_in_lista()
  391. test_numar_oferte()
  392. test_medie_pret()
  393. test_sterge_pret()
  394. test_sterge_zile()
  395. test_sterge_pachet_dest()
  396. test_verificare_sters_zile()
  397. test_verificare_sters_dest()
  398. test_verificare_sters_luna()
  399.  
  400.  
  401. def to_str_pachet(pachet):
  402. return str(
  403. "Data de inceput: " + str(pachet["data_i"]) + "\n" + "Data de sfarsit: " + str(
  404. pachet["data_s"]) + "\n" + "Destinatia: " +
  405. pachet["dest"] + "\n" + "Pretul: " + str((pachet["pret"])))
  406.  
  407.  
  408. def to_int_data_i(pachet):
  409. # functie care returneaza int-ul din data de inceput
  410. # e.g. daca avem data de inceput data_i = 25-10-2021, functia va returna 20211025
  411. return 10000 * get_data_i(pachet).year + 100 * get_data_i(pachet).month + get_data_i(pachet).day
  412.  
  413.  
  414. def to_int_data_s(pachet):
  415. # functie care returneaza int-ul din data de sfarsit
  416. # e.g. daca avem data de sfarsit data_i = 25-10-2021, functia va returna 20211025
  417. return 10000 * get_data_s(pachet).year + 100 * get_data_s(pachet).month + get_data_s(pachet).day
  418.  
  419.  
  420. def verifica_zile_int(pachet):
  421. # functie care verifica numarul de zile pt 2 date de de inceput si de sfarsit
  422. return to_int_data_s(pachet) - to_int_data_i(pachet)
  423.  
  424.  
  425. def medie_pret(l, dest_user_i):
  426. # functie ce returneaza media de pret pentru o destinatie data
  427. suma_pret = 0
  428. nr_dest = 0
  429. for _pachet in l:
  430. if get_destinatie(_pachet) == dest_user_i:
  431. suma_pret += get_pret(_pachet)
  432. nr_dest += 1
  433. if nr_dest == 0:
  434. return get_pret(_pachet)
  435. try:
  436. return float(suma_pret / nr_dest)
  437. except ZeroDivisionError:
  438. print("Date introduse gresit!\n")
  439.  
  440.  
  441. def numar_oferte(l):
  442. # functie care calculeaza numarul de oferte pentru o locatie data
  443. nr_oferte = 0
  444. dest_input = str(input("Introduceti destinatia pe care vreti o sa cautati aici: "))
  445. for _pachet in l:
  446. if get_destinatie(_pachet) == dest_input:
  447. nr_oferte += 1
  448. print("Numarul de oferte pentru destinatia ", dest_input, "este ", nr_oferte)
  449.  
  450.  
  451. def verifica_pret(pachet, user_input):
  452. return get_pret(pachet) > user_input
  453.  
  454.  
  455. def verifica_dest(pachet, user_input):
  456. return get_destinatie(pachet) == user_input
  457.  
  458.  
  459. def verifica_zile(pachet, user_input):
  460. return verifica_zile_int(pachet) <= user_input
  461.  
  462.  
  463. def verifica_luna(pachet, luna_user_i):
  464. return get_data_i(pachet).month == luna_user_i and get_data_i(pachet).month == luna_user_i or get_data_s(
  465. pachet).month == luna_user_i and get_data_s(pachet) == luna_user_i
  466.  
  467.  
  468. def sterge_pret(l, user_input):
  469. # functie care sterge pachetele care au un pret mai mare decat user_input
  470. l[:] = [pachet for pachet in l if not (verifica_pret(pachet, user_input))]
  471. return l
  472.  
  473.  
  474. def sterge_pachet_dest(l, user_input):
  475. # functie care sterge pachetele cu aceeasi destinatie ca si user_input
  476. l[:] = [pachet for pachet in l if not (verifica_dest(pachet, user_input))]
  477. return l
  478.  
  479.  
  480. def sterge_zile(l, user_input):
  481. # functie care sterge pachetele cu acelasi numar de zile ca si user_input
  482. l[:] = [pachet for pachet in l if not (verifica_zile(pachet, user_input))]
  483. return l
  484.  
  485.  
  486. def eliminare_luna(l, user_input):
  487. # functie care sterge pachetele cu aceeasi luna ca si luna_user_i
  488. l[:] = [pachet for pachet in l if not verifica_luna(pachet, user_input)]
  489. return l
  490.  
  491.  
  492. def creeaza_lista_cu_pachete(l,user_input,lst):
  493. old_i = 0
  494. for el,pachet in enumerate(l):
  495. if verificare_sters_luna(l,user_input) or verificare_sters_zile(l,user_input) or verificare_sters_dest(l,user_input):
  496. lst.append(l[el])
  497. return lst
  498.  
  499.  
  500.  
  501.  
  502. def undo(l):
  503. pass
  504.  
  505.  
  506. def ui_adauga_pachet(l):
  507. try:
  508. data_i = input("Introduceti data de inceput in formatul dd-mm-yyyy: ")
  509. data_i = datetime.datetime.strptime(data_i, "%d-%m-%Y").date()
  510. data_s = input("Introduceti data de sfarsit in formatul dd-mm-yyyy: ")
  511. data_s = datetime.datetime.strptime(data_s, "%d-%m-%Y").date()
  512. except ValueError:
  513. print("date numerice invalide!")
  514. return
  515. dest = input("Introduceti destinatia aici: ")
  516. try:
  517. pret = float(input("Introduceti pretul aici: "))
  518. except ValueError:
  519. print("pret invalid!")
  520. return
  521. srv_adauga_pachet_in_lista(l, data_i, data_s, dest, pret)
  522.  
  523.  
  524. def ui_print_pachet(l):
  525. for pachet in l:
  526. print(to_str_pachet(pachet))
  527. if len(l) == 0:
  528. print("Nu a fost introdus niciun pachet!")
  529.  
  530.  
  531. def ui_modifica_date(l):
  532. print("Pachete introduse pana acum: ")
  533. for el, pachet in enumerate(l, start=1):
  534. print(f"{el}.{pachet}")
  535. alegere_mod = int(input("alegeti ce pachet vreti sa modificati: "))
  536. print("Se va modifica pachetul: ", alegere_mod, l[alegere_mod - 1])
  537. l.remove(l[alegere_mod - 1])
  538. ui_adauga_pachet(l)
  539.  
  540.  
  541. def ui_sterge_pachet_dest(l):
  542. if len(l) == 0:
  543. print("nu exista niciun pachet de sters")
  544. else:
  545. user_input = str(input("Introduceti destinatia pachetului pe care vreti sa il stergeti: "))
  546. print("Se vor sterge pachetele cu destinatia: ", user_input)
  547. sterge_pachet_dest(l, user_input)
  548.  
  549.  
  550. def ui_sterge_zile(l):
  551. if len(l) == 0:
  552. print("nu exista niciun pachet de sters")
  553. else:
  554. user_input = int(input("Introduceti zilele pachetului pe care vreti sa il stergeti: "))
  555. print("Se vor sterge pachetele cu destinatia: ", user_input)
  556. sterge_zile(l, user_input)
  557.  
  558.  
  559. def ui_sterge_pret(l):
  560. if len(l) == 0:
  561. print("nu exista niciun pachet de sters")
  562. else:
  563. user_input = float(input("Introduceti pretul pachetului pe care vreti sa il stergeti: "))
  564. print("Se vor sterge pachetele care au pretul mai mare decat: ", user_input)
  565. sterge_pret(l, user_input,el)
  566. print("Lista pachetelor care au fost sterse este", lst)
  567.  
  568.  
  569. def ui_numar_oferte(l):
  570. if len(l) == 0:
  571. print("Nu a fost introdus niciun pachet!")
  572. else:
  573. numar_oferte(l)
  574.  
  575.  
  576. def ui_medie_pret(l):
  577. if len(l) == 0:
  578. print("Nu a fost introdus niciun pachet!")
  579. else:
  580. dest_user_i = str(input("Introduceti destinatia pe care vreti sa o cautati aici: "))
  581. print("Media pretului este ", medie_pret(l, dest_user_i))
  582.  
  583.  
  584. def ui_eliminare_luna(l):
  585. if len(l) == 0:
  586. print("Nu a fost introdus niciun pachet!")
  587. else:
  588. user_input = int(input("Introduceti luna pachetelor pe care vreti sa le stergeti: "))
  589. eliminare_luna(l, user_input)
  590. print("Au fost sters(e) pachetele")
  591.  
  592.  
  593. def verificare_sters_luna(l,user_input):
  594. global ok
  595. ok = False
  596. if eliminare_luna(l,user_input):
  597. ok = True
  598. return ok
  599.  
  600.  
  601. def verificare_sters_dest(l,user_input):
  602. global ok
  603. ok = False
  604. if sterge_pachet_dest(l,user_input):
  605. ok = True
  606. return ok
  607.  
  608.  
  609. def verificare_sters_zile(l,user_input):
  610. global ok
  611. ok = False
  612. if sterge_zile(l,user_input):
  613. ok = True
  614. return ok
  615.  
  616.  
  617. def ui_undo(l,user_input,lst):
  618. creeaza_lista_cu_pachete(l,user_input,lst)
  619.  
  620.  
  621. def run():
  622. l = []
  623. lst = []
  624. while True:
  625. cmd = input(">>>")
  626. if cmd == "exit":
  627. return
  628. if cmd == " ":
  629. continue
  630. if cmd == "add_pachet":
  631. try:
  632. ui_adauga_pachet(l)
  633. except Exception as ex:
  634. print(ex)
  635. elif cmd == "modifica_pachet":
  636. try:
  637. ui_modifica_date(l)
  638. except ValueError:
  639. print("date numerice invalide!")
  640. elif cmd == "print_pachete":
  641. ui_print_pachet(l)
  642. elif cmd == "sterge_dest":
  643. ui_sterge_pachet_dest(l)
  644. elif cmd == "sterge_zile":
  645. ui_sterge_zile(l)
  646. elif cmd == "sterge_pret":
  647. ui_sterge_pret(l)
  648. elif cmd == "numar_oferte":
  649. ui_numar_oferte(l)
  650. elif cmd == "medie_pret":
  651. ui_medie_pret(l)
  652. elif cmd == "eliminare_luna":
  653. ui_eliminare_luna(l)
  654. elif cmd == "modificare":
  655. ui_modifica_date(l)
  656. elif cmd == "undo":
  657. ui_undo(l,user_input,lst)
  658. else:
  659. print("comanda invalida!")
  660.  
  661. global ok
  662. def main():
  663. run()
  664. run_teste()
  665.  
  666.  
  667. main()
  668.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement