Question

PYHTON

Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-cPrescription class attributes: patient: the patients name (a string). drug.name: the medications name for the particular prPart V: EXTRA CREDIT: Find the Costliest Drug(s) (20 points) Write a function costliest.drugs that takes one argument, a Phartwo or more drugs will have the highest total value. Therefore, the function always returns a list of the names of the most e

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 dictionary that represents the drug inventory in a particular pharmacy. The dictionary maps the drug name (string) to its stock amount (integer) in units. The unit is adaptive, meaning that you don't need to worry about whether it counts in pills or milliliters or some other unit unit-prices: A dictionary that represents a look-up database that serves as a price book. The dictionary maps the drug name (string) to its unit price (integer). We will always assume that if a drug's name exists as a key in inventory, it will always exist as a key in unit-prices also. Note that the converse is not always true, however.
Prescription class attributes: patient: the patient's name (a string). drug.name: the medication's name for the particular prescription (a string) quantity: the quantity specified for the particular prescription (an integer)
Part V: EXTRA CREDIT: Find the Costliest Drug(s) (20 points) Write a function costliest.drugs that takes one argument, a Pharmacy object. The function searches the pharmacy for the drug with the highest total value as computed by multiplying the quantity of the drug on hand (using Pharmacy.inventory) by its unit price (using Pharmacy.unit-prices). It is possible that
two or more drugs will have the highest total value. Therefore, the function always returns a list of the names of the most expensive drugs. Even if only one drug has the maximum total value, its name is still returned in a list. Examples: Function Call costliest.drug (Pharmacy (Adderall': 731, Pantoprazole' 932, Singulair': 645, Nexium 308, 'Crestor: 613 Amoxicillin 562, 'Lisinopril': 808, 'Azithromycin' 415, 'Hydrochlorothiazide' : 993, Epogen 531, 'Losartan': 101, 'Amlodipine': 749, 'Hydrocodone' 652,Zocor': 169), {' Adderall' 33, 'Pantoprazole' 87, 'Singulair': 17, 'Nexium': 83, 'Crestor 64, Amoxicillin': 100, 'Lisinopril' 42, Azithromycin' 60, 'Hydrochlorothiazide 88, Epogen': 44, Losartan': 74, 'Amlodipine': 31, 'Hydrocodone': 96, 'Zocor': 38))) costliest.drug (Pharmacy (1' Seroquel': 404, Azithromycin': 925, 'Hydrochlorothiazide': 947, 'Crestor': 223, Metformin': 943, Gabapentin': 244, 'Amlodipine' 816, Synthroid': 995],{' 'Azithromycin': 61, 'Hydrochlorothiazide': 52, 'Crestor': 85, 'Metformin' 43, 'Gabapentin' 51, 'Amlodipine 41, Synthroid' 44 costliest.drug (Pharmacy ({'Azithromycin': 511, 'Advair Diskus' 843, 'Prilosec 718, 'Metformin': 690, 'Singulair' 974, Hydrochlorothiazide 528, 'Plavix': 533, 'Zocor' 784, 'Ciprofloxacin': 318, 'Amoxicillin': 820,Seroquel' 587, 'Abilify' 190), {'Azithromycin': 53, 'Advair Diskus': 95, 'Prilosec' 99, 'Metformin': 58, 'Singulair' 85, Hydrochlorothiazide' 86, 'Plavix': 25, ' Zocor'87, 'Ciprofloxacin': 49, 'Amoxicillin, : 51, 'Seroquel,: 56, Abilify,: 70})) Return Value [' Hydrochlorothiazide' ] [ 'Azithromycin' ] 'Seroquel'74, [' Singulair' ]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

class Pharmacy: def init_(self,inventory,unit_prices): self.inventoryinventory self.unit_prices-unit_prices def _repr(self):def costliest_drugs(ob): higheste for i in list(ob.inventory.keys): if ob.inventory[il*ob.unit prices[i highest: highest- ob.

Add a comment
Know the answer?
Add Answer to:
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)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT