CSE 101.02: Introduction to Computers Stony Brook University Spring 2019 Homework Assignment #5 Assignment Due: May 10, 2019 by 11:59 pm Learning Outcomes After completion of this homework assignment,...

1 answer below »
This codes need to pass all the cases


CSE 101.02: Introduction to Computers Stony Brook University Spring 2019 Homework Assignment #5 Assignment Due: May 10, 2019 by 11:59 pm Learning Outcomes After completion of this homework assignment, you should be able to: • Design and implement algorithms that work with classes and objects. • Implement a function that reads data from an input CSV (comma-separated values) file. 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: def __init__(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. Example dictionaries are given below. Different dictionaries will likely be used during grading: CSE 101 – Spring 2019 Homework #5 1 inventory = {’Hydrocodone’: 78, ’Zocor’ : 25, ’Lisinopril’: 150, ’Synthroid’ : 32, ’Norvasc’ : 100, ’Prilosec’ : 44, ’Azithromycin’ : 78, ’Amoxicillin’ : 26, ’Glucophage’ : 17, ’Hydrochlorothiazide’ : 39, ’Crestor’ : 28, ’Cymbalta’ : 55, ’Adderall’ : 0, ’Ibuprofen’ : 44} unit_prices = {’Hydrocodone’: 4, ’Zocor’ : 5, ’Lisinopril’: 10, ’Synthroid’ : 1, ’Norvasc’ : 4, ’Prilosec’ : 9, ’Azithromycin’ : 4, ’Amoxicillin’ : 8, ’Glucophage’ : 1, ’Hydrochlorothiazide’ : 13, ’Crestor’ : 12, ’Cymbalta’ : 9, ’Adderall’: 5} 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: Error Condition Return Value The quantity requested in the prescription is zero or negative. -1 The drug does not exist in the pharmacy’s inventory. (That is, the name is invalid.) -2 The stocked amount of the drug is not enough to fill the prescription. -3 Examples: Because the function arguments contain a lot of data, only a few test cases are given here. See the testing scripts for additional test cases. CSE 101 – Spring 2019 Homework #5 2 Function Call Return Value 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)) 520 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, ’Amlodipine’: 96, ’Hydrochlorothiazide’: 73, ’Crestor’: 60, ’Levothyroxine’: 86, ’Plavix’: 99, ’Metformin’: 63}) Function Call Return Value 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)) 177 Updated pharmacy value Pharmacy({’Seroquel’: 956, ’Lisinopril’: 485, ’Zocor’: 383, ’Amoxicillin’: 177, ’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}) Function Call Return Value dispense(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}), Prescription(’Yan’,’Advair Diskus’,-21)) -1 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}) CSE 101 – Spring 2019 Homework #5 3 Function Call Return Value dispense(Pharmacy({’Levothyroxine’: 976, ’Actos’: 697, ’Nexium’: 852, ’Glucophage’: 759, ’Ciprofloxacin’: 180, ’Pantoprazole’: 911},{’Levothyroxine’: 59, ’Actos’: 60, ’Nexium’: 38, ’Glucophage’: 81, ’Ciprofloxacin’: 53, ’Pantoprazole’: 93}), Prescription(’Rex’,’Synthroid’,499)) -2 Updated pharmacy value Pharmacy({’Levothyroxine’: 976, ’Actos’: 697, ’Nexium’: 852, ’Glucophage’: 759, ’Ciprofloxacin’: 180, ’Pantoprazole’: 911},{’Levothyroxine’: 59, ’Actos’: 60, ’Nexium’: 38, ’Glucophage’: 81, ’Ciprofloxacin’: 53, ’Pantoprazole’: 93}) Function Call Return Value dispense(Pharmacy({’Pantoprazole’: 125, ’Hydrochlorothiazide’: 978, ’Norvasc’: 999, ’Omeprazole’: 977, ’Amlodipine’: 141, ’Metformin’: 783},{’Pantoprazole’: 81, ’Hydrochlorothiazide’: 60, ’Norvasc’: 19, ’Omeprazole’: 34, ’Amlodipine’: 85, ’Metformin’: 30}), Prescription(’Erin’,’Norvasc’,1031)) -3 Updated pharmacy value Pharmacy({’Pantoprazole’: 125, ’Hydrochlorothiazide’: 978, ’Norvasc’: 999, ’Omeprazole’: 977, ’Amlodipine’: 141, ’Metformin’: 783},{’Pantoprazole’: 81, ’Hydrochlorothiazide’: 60, ’Norvasc’: 19, ’Omeprazole’: 34, ’Amlodipine’: 85, ’Metformin’: 30}) Please note that the test cases shown above are different from those that are given in the tester file. Part II: Dispense a Batch of Medications (20 points) Write a function batch dispense() that takes two arguments, in this order: • pharmacy: a Pharmacy object • prescriptions: a list of Prescription objects The function iterates through the list, inspects each individual Prescription object, and then dispenses the prescribed drugs by updating the inventory dictionary as needed. The function returns the total cost of all dispensed prescriptions in the list. To do so, the function will need to look up the unit prices of the drug in the unit prices dictionary in the pharmacy object. While the function is iterating over the prescriptions list, it is possible that errors arise due to invalid data (for example, there are not enough pills in stock to fill a prescription). In all invalid cases (see Part I for a complete list), simply skip that prescription and continue to inspect the remaining prescriptions. If all prescriptions are invalid, the function will return zero because they are all skipped. If the prescriptions list is empty, the function returns 0. CSE 101 – Spring 2019 Homework #5 4 Examples: Function Call Return Value batch dispense(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}), [Prescription(’Mack’, ’Zocor’, -27), Prescription(’Rachael’, ’Crestor’, 474), Prescription(’Janet’, ’Epogen’, 202), Prescription(’Dana’, ’Zocor’, 97), Prescription(’Dave’, ’Nexium’, 99)]) 51127 Updated pharmacy value Pharmacy({’Adderall’: 731, ’Pantoprazole’: 932, ’Singulair’: 645, ’Nexium’: 209, ’Crestor’: 139, ’Amoxicillin’: 562, ’Lisinopril’: 808, ’Azithromycin’: 415, ’Hydrochlorothiazide’: 993, ’Epogen’: 329, ’Losartan’: 101, ’Amlodipine’: 749, ’Hydrocodone’: 652, ’Zocor’: 72},{’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}) Function Call Return Value batch dispense(Pharmacy({’Advair Diskus’: 447, ’Gabapentin’: 702, ’Prilosec’: 511, ’Metformin’: 843, ’Singulair’: 718, ’Hydrochlorothiazide’: 690, ’Plavix’: 974, ’Zocor’: 528},{’Advair Diskus’: 46, ’Gabapentin’: 84, ’Prilosec’: 53, ’Metformin’: 95, ’Singulair’: 99, ’Hydrochlorothiazide’: 58, ’Plavix’: 85, ’Zocor’: 86}), [Prescription(’Frank’, ’Plavix’, 932), Prescription(’Crissy’, ’Metformin’, 276), Prescription(’Harry’, ’Singulair’, 693), Prescription(’Mike’, ’Crestor’, 476), Prescription(’Janet’, ’Metformin’, 912), Prescription(’Rachael’, ’Gabapentin’, 445), Prescription(’Timmy’, ’Metformin’, 580), Prescription(’Timmy’, ’Gabapentin’, 685), Prescription(’Robert’, ’Singulair’, 488)]) 211427 Updated pharmacy value Pharmacy({’Advair Diskus’: 447, ’Gabapentin’: 257, ’Prilosec’: 511, ’Metformin’: 567, ’Singulair’: 25, ’Hydrochlorothiazide’: 690, ’Plavix’: 42, ’Zocor’: 528},{’Advair Diskus’: 46, ’Gabapentin’: 84, ’Prilosec’: 53, ’Metformin’: 95, ’Singulair’: 99, ’Hydrochlorothiazide’: 58, ’Plavix’: 85, ’Zocor’: 86}) CSE 101 – Spring 2019 Homework #5 5 Function Call Return Value batch dispense(Pharmacy({’Pantoprazole’: 710, ’Glucophage’: 325, ’Amlodipine’: 521, ’Singulair’: 227, ’Lipitor’: 570, ’Gabapentin’: 447, ’Nexium’: 644, ’Zocor’: 686, ’Norvasc’: 553, ’Hydrocodone’: 284, ’Amoxicillin’: 418, ’Simvastatin’: 974, ’Seroquel’: 452},{’Pantoprazole’: 67, ’Glucophage’: 94, ’Amlodipine’: 93, ’Singulair’: 35, ’Lipitor’: 63, ’Gabapentin’: 50, ’Nexium’: 75, ’Zocor’: 40, ’Norvasc’: 27, ’Hydrocodone’: 47, ’Amoxicillin’: 85, ’Simvastatin’: 17, ’Seroquel’: 59}), [Prescription(’Lisa’, ’Lipitor’, -16), Prescription(’Robert’, ’Hydrocodone’, 164), Prescription(’Frank’, ’Gabapentin’, 476), Prescription(’Frank’, ’Zocor’, 580), Prescription(’Iris’, ’Pantoprazole’, 13), Prescription(’Iris’, ’Singulair’, 30), Prescription(’Frank’, ’Nexium’, 179), Prescription(’Barb’, ’Amoxicillin’, 216), Prescription(’Erin’, ’Seroquel’, 0), Prescription(’Mike’, ’Gabapentin’, 315), Prescription(’Lisa’, ’Simvastatin’, 993)]) 80364 Updated pharmacy value Pharmacy({’Pantoprazole’: 697, ’Glucophage’: 325, ’Amlodipine’: 521, ’Singulair’: 197, ’Lipitor’: 570, ’Gabapentin’: 132, ’Nexium’: 465, ’Zocor’: 106, ’Norvasc’: 553, ’Hydrocodone’: 120, ’Amoxicillin’: 202, ’Simvastatin’: 974, ’Seroquel’: 452},{’Pantoprazole’: 67, ’Glucophage’: 94, ’Amlodipine’: 93, ’Singulair’: 35, ’Lipitor’: 63, ’Gabapentin’: 50, ’Nexium’: 75, ’Zocor’: 40, ’Norvasc’: 27, ’Hydrocodone’: 47, ’Amoxicillin’: 85, ’Simvastatin’: 17
Answered Same DayMay 10, 2021

Answer To: CSE 101.02: Introduction to Computers Stony Brook University Spring 2019 Homework Assignment #5...

Samrakshini R answered on May 10 2021
154 Votes
homework5/__pycache__/homework5.cpython-37.pyc
homework5/__pycache__/homework5_classes.cpython-37.pyc
homework5/pharm4.csv
Crestor,59,392
Prilosec,45,399
Losartan,83,756
Hydrochlorothiazide,31,419
Epogen,92,842
Amoxicillin,70,126
Abilify,53,912
Azithromycin,41,199
Seroquel,99,692
Amlodipine,83,502
Synthroid,94,381
Glucophage,48,537
Actos,19,554
Nexium,16,235
__MACOSX/homework5/._pharm4.csv
homework5/pharm5.csv
Amoxicillin,35,227
Pantoprazole,63,570
Singulair,50,447
Lipitor,75,644
Gabapentin,40,686
Losartan,27,553
Simvastatin,47,284
Metformin,85,418
__MACOSX/homework5/._pharm5.csv
homework5/homework5_tester.py
import sys
from homework5_classes import *
student_file = 'homework5.py'
f = open(student_file)
lines = f.readlines()
f.close()
lines = [line.strip() for line in lines]
lines = ['' if line.startswith('#') else line for line in lines]
code_clean = True
for i in range(len(lines)):
if 'import' in lines[i] and
not (lines[i].endswith('math') or 'homework5_classes' in lines[i]):
print(f'Line {i} of {student_file} contains an import or eval() statement. You must delete this line.')
code_clean = False
elif 'input' in lines[i]:
print(f'Line {i} of {student_file} contains an input() statement. You must delete this line.')
code_clean = False
# elif 'open' in lines[i]:
# print(f'Line {i} of {student_file} contains an open() statement. You must delete this line.')
# code_clean = False
elif 'exit' in lines[i] or 'sys.exit' in lines[i]:
print(f'Line {i} of {student_file} contains an exit() statement. You must delete this line.')
code_clean = False
if not code_clean:
print('Your ' + student_file + ' file contains one or more invalid lines of code.')
print('You will need to remove them before running the driver.')
print('Note that the presence of those lines renders your work ungradeable!')
sys.exit()
def check_float_actual(exp, act):
if isinstance(act, float):
print('Actual return value: {:.2f}'.format(act))
else:
print(f'Actual return value: {act}')
if isinstance(act, float) and abs(exp - act) <= 0.01:
print('Correct!')
return True
elif not isinstance(act, float):
print('Incorrect! (wrong value and/or wrong return type)')
return False
else:
print('Incorrect!')
return False
part_counts = [0] * 5
test_counts = []
from homework5 import *
# Part I Tests
args = [[Pharmacy({'Metformin': 763, 'Amoxicillin': 502, 'Levothyroxine': 218, 'Hydrocodone': 898, 'Lipitor': 142},{'Metformin': 55, 'Amoxicillin': 82, 'Levothyroxine': 89, 'Hydrocodone': 33, 'Lipitor': 31}), Prescription('Rachael', 'Metformin', 137)], [Pharmacy({'Ciprofloxacin': 152, 'Lipitor': 848, 'Norvasc': 493, 'Abilify': 632, 'Azithromycin': 439, 'Epogen': 198, 'Advair Diskus': 662, 'Zocor': 616, 'Actos': 623, 'Amoxicillin': 508, 'Synthroid': 429, 'Hydrocodone': 695, 'Seroquel': 399, 'Nexium': 773},{'Ciprofloxacin': 46, 'Lipitor': 88, 'Norvasc': 87, 'Abilify': 54, 'Azithromycin': 91, 'Epogen': 18, 'Advair Diskus': 29, 'Zocor': 35, 'Actos': 23, 'Amoxicillin': 86, 'Synthroid': 75, 'Hydrocodone': 54, 'Seroquel': 28, 'Nexium': 63}), Prescription('Pat', 'Synthroid', 220)], [Pharmacy({'Advair Diskus': 782, 'Epogen': 550, 'Crestor': 805, 'Norvasc': 551, 'Metformin': 296, 'Adderall': 183, 'Nexium': 873, 'Glucophage': 833, 'Hydrocodone': 407},{'Advair Diskus': 78, 'Epogen': 49, 'Crestor': 73, 'Norvasc': 40, 'Metformin': 29, 'Adderall': 58, 'Nexium': 65, 'Glucophage': 59, 'Hydrocodone': 72}), Prescription('Dana', 'Hydrocodone', 121)], [Pharmacy({'Hydrochlorothiazide': 341, 'Glucophage': 779, 'Lipitor': 375, 'Actos': 318, 'Metformin': 598, 'Amlodipine': 701},{'Hydrochlorothiazide': 68, 'Glucophage': 43, 'Lipitor': 21, 'Actos': 41, 'Metformin': 84, 'Amlodipine': 33}), Prescription('Barb', 'Amlodipine', 443)], [Pharmacy({'Gabapentin': 355, 'Hydrochlorothiazide': 405, 'Omeprazole': 672, 'Adderall': 204, 'Azithromycin': 674, 'Advair Diskus': 314, 'Amoxicillin': 828, 'Abilify': 718, 'Glucophage': 850, 'Amlodipine': 198, 'Norvasc': 458, 'Lisinopril': 975, 'Hydrocodone': 974, 'Zocor': 152},{'Gabapentin': 78, 'Hydrochlorothiazide': 56, 'Omeprazole': 78, 'Adderall': 72, 'Azithromycin': 31, 'Advair Diskus': 20, 'Amoxicillin': 27, 'Abilify': 58, 'Glucophage': 64, 'Amlodipine': 73, 'Norvasc': 64, 'Lisinopril': 38, 'Hydrocodone': 73, 'Zocor': 39}), Prescription('Robert', 'Hydrocodone', 175)], [Pharmacy({'Omeprazole': 800, 'Crestor': 831, 'Plavix': 233, 'Metformin': 604, 'Actos': 880, 'Adderall': 416, 'Hydrochlorothiazide': 800, 'Nexium': 144, 'Levothyroxine': 902, 'Gabapentin': 293, 'Lipitor': 431, 'Abilify': 406, 'Seroquel': 822},{'Omeprazole': 100, 'Crestor': 52, 'Plavix': 57, 'Metformin': 87, 'Actos': 24, 'Adderall': 42, 'Hydrochlorothiazide': 79, 'Nexium': 38, 'Levothyroxine': 62, 'Gabapentin': 60, 'Lipitor': 62, 'Abilify': 73, 'Seroquel': 98}), Prescription('William', 'Seroquel', 423)], [Pharmacy({'Singulair': 165, 'Lisinopril': 933, 'Synthroid': 361, 'Epogen': 522, 'Amoxicillin': 957, 'Adderall': 322, 'Plavix': 751, 'Hydrochlorothiazide': 892, 'Gabapentin': 435, 'Omeprazole': 848, 'Ciprofloxacin': 369, 'Levothyroxine': 817, 'Norvasc': 763, 'Lipitor': 195, 'Losartan': 595},{'Singulair': 31, 'Lisinopril': 96, 'Synthroid': 33, 'Epogen': 67, 'Amoxicillin': 88, 'Adderall': 48, 'Plavix': 80, 'Hydrochlorothiazide': 80, 'Gabapentin': 90, 'Omeprazole': 71, 'Ciprofloxacin': 46, 'Levothyroxine': 30, 'Norvasc': 71, 'Lipitor': 34, 'Losartan': 95}), Prescription('Rex', 'Gabapentin', 313)], [Pharmacy({'Actos': 673, 'Synthroid': 622, 'Epogen': 357, 'Hydrochlorothiazide': 652, 'Singulair': 331},{'Actos': 100, 'Synthroid': 63, 'Epogen': 95, 'Hydrochlorothiazide': 61, 'Singulair': 54}), Prescription('Timmy', 'Synthroid', -26)], [Pharmacy({'Plavix': 214, 'Gabapentin': 890, 'Azithromycin': 943, 'Glucophage': 813, 'Synthroid': 750, 'Prilosec': 788, 'Pantoprazole': 920, 'Lisinopril': 848, 'Actos': 522, 'Simvastatin': 165},{'Plavix': 40, 'Gabapentin': 86, 'Azithromycin': 26, 'Glucophage': 90, 'Synthroid': 80, 'Prilosec': 54, 'Pantoprazole': 19, 'Lisinopril': 86, 'Actos': 40, 'Simvastatin': 95}), Prescription('Terry', 'Advair Diskus', 229)], [Pharmacy({'Amlodipine': 351, 'Hydrocodone': 158, 'Losartan': 107, 'Simvastatin': 351, 'Crestor': 795, 'Lipitor': 586, 'Seroquel': 144, 'Plavix': 265, 'Nexium': 415, 'Hydrochlorothiazide': 917},{'Amlodipine': 53, 'Hydrocodone': 45, 'Losartan': 55, 'Simvastatin': 64, 'Crestor': 60, 'Lipitor': 84, 'Seroquel': 34, 'Plavix': 64, 'Nexium': 28, 'Hydrochlorothiazide': 96}), Prescription('Erin', 'Losartan', 117)], ]
expected_return_values = [626, 209, 286, 258, 799, 399, 122, -1, -2, -3, ]
expected_inventory_dicts = [{'Metformin': 626, 'Amoxicillin': 502, 'Levothyroxine': 218, 'Hydrocodone': 898, 'Lipitor': 142}, {'Ciprofloxacin': 152, 'Lipitor': 848, 'Norvasc': 493, 'Abilify': 632, 'Azithromycin': 439, 'Epogen': 198, 'Advair Diskus': 662, 'Zocor': 616, 'Actos': 623, 'Amoxicillin': 508, 'Synthroid': 209, 'Hydrocodone': 695, 'Seroquel': 399, 'Nexium': 773}, {'Advair Diskus': 782, 'Epogen': 550, 'Crestor': 805, 'Norvasc': 551, 'Metformin': 296, 'Adderall': 183, 'Nexium': 873, 'Glucophage': 833, 'Hydrocodone': 286}, {'Hydrochlorothiazide': 341, 'Glucophage': 779, 'Lipitor': 375, 'Actos': 318, 'Metformin': 598, 'Amlodipine': 258}, {'Gabapentin': 355, 'Hydrochlorothiazide': 405, 'Omeprazole': 672, 'Adderall': 204, 'Azithromycin': 674, 'Advair Diskus': 314, 'Amoxicillin': 828, 'Abilify': 718, 'Glucophage': 850, 'Amlodipine': 198, 'Norvasc': 458, 'Lisinopril': 975, 'Hydrocodone': 799, 'Zocor': 152}, {'Omeprazole': 800, 'Crestor': 831, 'Plavix': 233, 'Metformin': 604, 'Actos': 880, 'Adderall': 416, 'Hydrochlorothiazide': 800, 'Nexium': 144, 'Levothyroxine': 902, 'Gabapentin': 293, 'Lipitor': 431, 'Abilify': 406, 'Seroquel': 399}, {'Singulair': 165, 'Lisinopril': 933, 'Synthroid': 361, 'Epogen': 522, 'Amoxicillin': 957, 'Adderall': 322, 'Plavix': 751, 'Hydrochlorothiazide': 892, 'Gabapentin': 122, 'Omeprazole': 848, 'Ciprofloxacin': 369, 'Levothyroxine': 817, 'Norvasc': 763, 'Lipitor': 195, 'Losartan': 595}, {'Actos': 673, 'Synthroid': 622, 'Epogen': 357, 'Hydrochlorothiazide': 652, 'Singulair': 331}, {'Plavix': 214, 'Gabapentin': 890, 'Azithromycin': 943, 'Glucophage': 813, 'Synthroid': 750, 'Prilosec': 788, 'Pantoprazole': 920, 'Lisinopril': 848, 'Actos': 522, 'Simvastatin': 165}, {'Amlodipine': 351, 'Hydrocodone': 158, 'Losartan': 107, 'Simvastatin': 351, 'Crestor': 795, 'Lipitor': 586, 'Seroquel': 144, 'Plavix': 265, 'Nexium': 415, 'Hydrochlorothiazide': 917}, ]
test_counts.append(len(args))
func = dispense
print('#' * 25 + ' Testing Part I ' + '#' * 25)
for arg_list, expected_ret, expected_dict in zip(args, expected_return_values, expected_inventory_dicts):
print(f'Testing {func.__name__}() with:\n pharmacy = {arg_list[0]}\n prescription = {arg_list[1]}')
print(f'Expected return value: {expected_ret}')
actual_ret = func(*arg_list)
print(f'Actual return value: {actual_ret}')
print(f'Expected inventory dict: {expected_dict}')
print(f'Actual inventory dict: {arg_list[0].inventory}')
if expected_ret == actual_ret and expected_dict == arg_list[0].inventory:
part_counts[0] += 1
print('Correct!')
if expected_ret != actual_ret:
print('Incorrect return value and/or wrong return type.')
if expected_dict != arg_list[0].inventory:
print('Drug inventory not updated correctly.')
print()
print('#' * 66)
print()
# Part II...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here