Advertisement
vallec

2

Jan 9th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. class Medicine:
  2. def __init__(self, med_id, med_name, manufacturer, price, quantity):
  3. self.med_id = med_id
  4. self.med_name = med_name
  5. self.manufacturer = manufacturer
  6. self.price = price
  7. self.quantity = quantity
  8.  
  9. def __str__(self):
  10. return f"ID: {self.med_id} Name: {self.med_name} Manufacturer: {self.manufacturer} Price:{str(round(self.price, 2))} Quantity: {self.quantity}"
  11. def __repr__(self):
  12. return f"ID: {self.med_id} Name: {self.med_name} Manufacturer: {self.manufacturer} Price:{str(round(self.price, 2))} Quantity: {self.quantity}"
  13. def Display(self):
  14. print(self)
  15. def Search_by_name(self, name):
  16. if(self.med_name == name):
  17. self.Display()
  18. def Sale(self, quantity):
  19. if(quantity <= 0):
  20. print("Vavedete validno kolichestvo!")
  21. elif(self.quantity >= quantity):
  22. self.quantity = self.quantity - quantity
  23. print(f"Uspeshno prodadohte {quantity} broq ot lekarstvo {self.med_name}")
  24. else:
  25. print("Nedostatuchno kolichestvo!")
  26. def Purchase(self, quantity):
  27. if(quantity <= 0):
  28. print("Vavedete validno kolichestvo!")
  29. else:
  30. self.quantity = self.quantity + quantity
  31. print(f"Uspeshno zakupihte {quantity} broq ot lekarstvo {self.med_name}")
  32.  
  33.  
  34. med_list = []
  35.  
  36. def Sort_Meds():
  37. print(sorted(med_list, key= lambda x: x.med_name))
  38.  
  39. while True:
  40. try:
  41. n = int(input("Vavedi broi lekarstva: "))
  42. if(n <= 0):
  43. raise Exception("Vavedi validno chislo!")
  44. except ValueError:
  45. print('Nevalidno chislo!')
  46. break
  47. except Exception:
  48. print("Nevalidni vhodni danni")
  49. break
  50.  
  51. for i in range(n):
  52. print(f"Lekarstvo NO. {i+1}")
  53. med_id = int(input("Vavedi ID: "))
  54. med_name = input("Vavedi ime: ")
  55. manufacturer = input("Vavedi proizvoditel: ")
  56. price = float(input("Vavedi cena: "))
  57. quantity = int(input("Vavedi kolichestvo: "))
  58.  
  59. med_list.append(Medicine(med_id, med_name, manufacturer, price, quantity))
  60.  
  61. med_list[0].Display()
  62. med_list[0].Sale(2)
  63. med_list[1].Purchase(8)
  64. print(med_list)
  65. Sort_Meds()
  66. print(med_list)
  67. break
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement