PYHTON
Code:
class Pharmacy: def __init__(self,inventory,unit_prices): self.inventory = inventory self.unit_prices = unit_prices def __repr__(self): return f'Pharmacy("{self.inventory}", {self.unit_prices})' def initialise_pharmacy(filename): inventory,unit_prices = {},{} fh = open(filename,'r') for line in fh.readlines(): name,price,quantity = line.split(',') price = int(price) quantity = int(quantity) inventory[name] = quantity unit_prices[name] = price fh.close() pharmacy_object = Pharmacy(inventory,unit_prices) return pharmacy_object initialise_pharmacy('pharm1.csv')
def costliest_drugs(ob): highest = 0 for i in list(ob.inventory.keys()): if ob.inventory[i]*ob.unit_prices[i]>highest: highest = ob.inventory[i]*ob.unit_prices[i] l = [] for i in list(ob.inventory.keys()): if ob.inventory[i]*ob.unit_prices[i]==highest: l.append(i) return l ph = initialise_pharmacy('pharm1.csv') costliest_drugs(ph)
File: pharm1.csv save it before running code
Adderall,33,731
Pantoprazole,87,932
Singulair,17,645
Nexium,83,308
Crestor,64,613
Amoxicillin,100,562
Lisinopril,42,808
Azithromycin,60,415
Hydrochlorothiazide,88,993
Epogen,44,531
Losartan,74,101
Amlodipine,31,749
Hydrocodone,96,652
Zocor,38,169
Output:
PYHTON Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-classes.py: class Pharmacy: def _init_(self, inventory, unit_prices)...
python Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-classes.py: class Pharmacy: def _init_(self, inventory, unit_prices) self.inventory - inventory self.unit_prices-unit_prices class Prescription: definit_(self, patient, drug_name, quantity): self.patient- patient self.drug_namedrug_name self.quantity - quantity You will be asked to write several functions that work with the Prescription and Pharmacy classes. To complete this assignment you may write any helper functions you like inside your homework5.py file. Pharmacy class attributes: * inventory: A...
Please have the function written in python, thank you! Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5.classes.py: class Pharmacy: det init (selt, inventory, unit_prices) self.inventory -inventory self.unit_pricesunit_prices class Prescription: definit_(self, patient, drug_name, quantity): self.patient patient self.drug_name - drug_name self.quantity -quantity You will be asked to write several functions that work with the Prescription and Pharmacy classes. To complete this assignment you may write any helper functions you like inside...