Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Medicine:
- def __init__(self, med_id, med_name, manufacturer, price, quantity):
- self.med_id = med_id
- self.med_name = med_name
- self.manufacturer = manufacturer
- self.price = price
- self.quantity = quantity
- def __str__(self):
- return f"ID: {self.med_id} Name: {self.med_name} Manufacturer: {self.manufacturer} Price:{str(round(self.price, 2))} Quantity: {self.quantity}"
- def __repr__(self):
- return f"ID: {self.med_id} Name: {self.med_name} Manufacturer: {self.manufacturer} Price:{str(round(self.price, 2))} Quantity: {self.quantity}"
- def Display(self):
- print(self)
- def Search_by_name(self, name):
- if(self.med_name == name):
- self.Display()
- def Sale(self, quantity):
- if(quantity <= 0):
- print("Vavedete validno kolichestvo!")
- elif(self.quantity >= quantity):
- self.quantity = self.quantity - quantity
- print(f"Uspeshno prodadohte {quantity} broq ot lekarstvo {self.med_name}")
- else:
- print("Nedostatuchno kolichestvo!")
- def Purchase(self, quantity):
- if(quantity <= 0):
- print("Vavedete validno kolichestvo!")
- else:
- self.quantity = self.quantity + quantity
- print(f"Uspeshno zakupihte {quantity} broq ot lekarstvo {self.med_name}")
- med_list = []
- def Sort_Meds():
- print(sorted(med_list, key= lambda x: x.med_name))
- while True:
- try:
- n = int(input("Vavedi broi lekarstva: "))
- if(n <= 0):
- raise Exception("Vavedi validno chislo!")
- except ValueError:
- print('Nevalidno chislo!')
- break
- except Exception:
- print("Nevalidni vhodni danni")
- break
- for i in range(n):
- print(f"Lekarstvo NO. {i+1}")
- med_id = int(input("Vavedi ID: "))
- med_name = input("Vavedi ime: ")
- manufacturer = input("Vavedi proizvoditel: ")
- price = float(input("Vavedi cena: "))
- quantity = int(input("Vavedi kolichestvo: "))
- med_list.append(Medicine(med_id, med_name, manufacturer, price, quantity))
- med_list[0].Display()
- med_list[0].Sale(2)
- med_list[1].Purchase(8)
- print(med_list)
- Sort_Meds()
- print(med_list)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement