Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 3: Robust Change (5 points) Complete following function according to the specification in the documentation string. You will need to create your own custom
Question 3: Robust Change (5 points)
Complete following function according to the specification in the documentation string. You will need to create your own custom exceptions for these functions.
Question 3: Robust Change (5 points) Complete following function according to the specification in the documentation string. You will need to create your own custom exceptions for these function:s In [ ]: # Write your answers here. Define ChangeParameterError and ChangeRemainderError in this code cell as well. def change1(a, d): Computes the change of amount a given denominations d. Parameter a must be of type int, d must be of type list of int, and the elements of d must be in ascending order, otherwise ChangeParameterError is raised. The result is a dictionary with keys from d, mapping to values of the number of coins/ bills of each denominatiorn This is computed by first taking the maximal number of coins/bil1 of the highest denomination, then the next highest, etc If no exact change is possible, ChangeRemainderError is raised return In [ ] : change(3, [3, 7]) (3: 1, 7: e} In [ ] : change(15, [1, 3, 7]) --(1: 1, 3: e, 7: 2) In [ J: try change(True, [4]) # raises changeParameterError except ChangeParameterError: print( Successful test case") In I : try change(3, 7) # raises ChangeParameterError except ChangeParameterError: print(" Successful test case") Question 3: Robust Change (5 points) Complete following function according to the specification in the documentation string. You will need to create your own custom exceptions for these function:s In [ ]: # Write your answers here. Define ChangeParameterError and ChangeRemainderError in this code cell as well. def change1(a, d): Computes the change of amount a given denominations d. Parameter a must be of type int, d must be of type list of int, and the elements of d must be in ascending order, otherwise ChangeParameterError is raised. The result is a dictionary with keys from d, mapping to values of the number of coins/ bills of each denominatiorn This is computed by first taking the maximal number of coins/bil1 of the highest denomination, then the next highest, etc If no exact change is possible, ChangeRemainderError is raised return In [ ] : change(3, [3, 7]) (3: 1, 7: e} In [ ] : change(15, [1, 3, 7]) --(1: 1, 3: e, 7: 2) In [ J: try change(True, [4]) # raises changeParameterError except ChangeParameterError: print( Successful test case") In I : try change(3, 7) # raises ChangeParameterError except ChangeParameterError: print(" Successful test case")Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started