Question

pythonPreliminaries 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 I: Dispense Medication (20 points) Write a function dispense ) that takes two arguments, in this order: pharmacy: a PharFunction Call dispense (Pharmacy (Nexium: 915, Epogen 619, Singulair 827,Lipitor 920, Gabapentin: 982, Amlodipine: 62

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 I: Dispense Medication (20 points) Write a function dispense ) that takes two arguments, in this order: pharmacy: a Pharmacy object prescription: a Prescription object The function reads the fields from the prescription object and updates the stocked amount of the drug in the pharmacy object's inventory dictionary. After updating the correct stocked amount of the drug in the inventory dictionary, the function returns the updated stocked amount. The function must be able to handle the following error conditions. The associated return value must be returned when a given error condition is present. The arguments must be left unchanged when an error occurs. Check for the error conditions in the order given: Return Value Error Condition The quantity requested in the prescription is zero or negative. The drug does not exist in the pharmacy's inventory. (That is, the name is invalid.) The stocked amount of the drug is not enough to fill the prescription. 2
Function Call dispense (Pharmacy ('Nexium': 915, 'Epogen' 619, Singulair 827,'Lipitor 920, Gabapentin': 982, 'Amlodipine': 629, 'Hydrochlorothiazide': 426, Crestor' 856, 'Levothyroxine' 822, Plavix': 134, 'Metformin': 780}, ' Nexium 68, Epogen' 92, Singulair' 25, 'Lipitor'22, Gabapentin': 58, Amlodipine' 96, 'Hydrochlorothiazide': 73, Crestor': 60, 'Levothyroxine' 86, 'Plavix': 99, 'Metformin' 63), Prescription ('Timmy", ' Gabapentin', 462)) Updated pharmacy value Pharmacy (Nexium 915, 'Epogen 619, 'Singulair' 827, 'Lipitor': 920, Gabapentin': 520, 'Amlodipine' 629, Hydrochlorothiazide': 426, Crestor 856, 'Levothyroxine 822, 'Plavix 134, 'Metformin': 780,'Nexium' 68 'Epogen' 92, 'Singulair': 25, 'Lipitor' 22, Gabapentin': 58, 'Amlodipine96, 'Hydrochlorothiazide' 73, Crestor' 60, 'Levothyroxine' 86, 'Plavix': 99, Metformin': 63ł) Function Call dispense (Pharmacy Seroquel' 956, 'Lisinopril': 485, Zocor 383, 'Amoxicillin' 178, 'Nexium' 697, 'Simvastatin' 458, 'Amlodipine 664, 'Azithromycin': 870, 'Abilify' 995), {' Seroquel' 40, 'Lisinopril': 28, 'Zocor 99, Amoxicillin' 37, 'Nexium': 20, Simvastatin': 35, 'Amlodipine' 67, 'Azithromycin: 86, 'Abilify' 46]), Prescription ('Lisa', 'Amoxicillin',1)) Updated pharmacy value PharmacySeroquel' 956, 'Lisinopril' 485, 'Zocor 383, 'Amoxicillin': 177, ,Nexium,: 697, 'Simvastatin, : 458, , Amlodǐpǐne': 664, 'Azithromycin' 870, Abilify': 995], {' Seroquel' 40, Lisinopril': 28, 'Zocor' 99, Amoxicillin': 37, 'Nexium 20, , Simvastatin': 35, 'Amlodipine': 67, 'Azithromycin': 86, 'Abilify': 46}) Function Call dispense (PharmacyGabapentin' 770, 'Levothyroxine': 560, 'Plavix' 560, Simvastatin': 504, Amoxicillin': 340, 'Metformin' 703, 'Glucophage 428, 'Advair Diskus' 445}, {Gabapentin' 70, 'Levothyroxine' 92, Plavix': 24, 'Simvastatin 49, 'Amoxicillin': 54, Metformin' 41, 'Glucophage': 58, 'Advair Diskus' 62}), Prescription (' Yan', 'Advair Diskus',-21)) Updated pharmacy value Pharmacy ( Gabapentin' 770, 'Levothyroxine': 560, 'Plavix': 560, 'Simvastatin':504, 'Amoxicillin'340, 'Metformin' 703, 'Glucophage 428, 'Advair Diskus' 445), {'Gabapentin': 70, Levothyroxine' 92, 'Plavix' 24, 'Simvastatin': 49,Amoxicillin': 54, 'Metformin' 41, 'Glucophage' 58, 'Advair Diskus' 62)) Return Value 520 Return Value Return Value
0 0
Add a comment Improve this question Transcribed image text
Answer #1

'''

Python version : 2.7

Python program to create a function dispense

'''

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 dispense(pharmacy, prescription):

              

               if prescription.quantity <= 0 :

                              return -1

                             

               else:

                             

                              drug_names = pharmacy.inventory.keys()

                              if prescription.drug_name not in drug_names:

                                             return -2

                              else:

                                             if pharmacy.inventory[prescription.drug_name] < prescription.quantity:

                                                            return -3

                                             else:

                                                            pharmacy.inventory[prescription.drug_name] = pharmacy.inventory[prescription.drug_name] - prescription.quantity

                                                            return pharmacy.inventory[prescription.drug_name]

                                                           

#end of program

Code Screenshot:

2 Python version 2.7 3 Python program to create a function dispense 6 class Pharmacy def init self-inventory inventory self.u

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