Question

Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5.cWrite a function costliest.drugs ) that takes one argument, a Pharmacy object. The function searches the pharmacy for the dru

two or more drugs will have the highest total value. Therefore, the function always returns a list of the names of the most e

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 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
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, rNexium': 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))) Return Value [' Hydrochlorothiazide' ]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the implemented function

=============================================================================

class Pharmacy:
    def __init__(self,inventory,unit_prices):
        self.inventory=inventory
        self.unit_prices=unit_prices
class Prescription:
    def __init__(self,patient,drug_name,quantity):
        self.patient=patient
        self.drug_name=drug_name
        self.quantity=quantity


def costliest_drugs(pharmacy):
    inventory=pharmacy.inventory
    max_quantity=0
    drug_name_with_max_count=0
    for drug_name,quantity in inventory.items():
        if max_quantity<quantity:
            max_quantity=quantity
            drug_name_with_max_count=drug_name
    return drug_name_with_max_count



def restock_drug(pharmacy,drug_name,quantity):
    if quantity<=0:
        return -1
    inventory =pharmacy.inventory
    unit_prices=pharmacy.unit_prices
    if drug_name not in unit_prices.keys():
        return -4
    if drug_name not in inventory.keys():
        inventory[drug_name]=quantity
    else:
        inventory[drug_name]+=quantity
    return inventory.get(drug_name)

=============================================================================

def costliest_drugs (pharmacy) inventory-pharmacy. inventory max-quantity-0 drug_name_with max_count-0 for drug name, quantit

thanks !

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