python
'''
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:
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)...
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) 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...