Answered step by step
Verified Expert Solution
Question
1 Approved Answer
After the following code is run, what are the values of n 1 and n 2 ? Note: we use some dictionary methods like dict.get
After the following code is run, what are the values of n and n
Note: we use some dictionary methods like dict.get and dict.setdefault in this code snippet because HuskyCT does not allow square brackets in question text. It is better in general to use square brackets for getting and setting items in a dictionary, unless you need the extra functionality provided by these methods.
def fewestcoinsamt coins, solveddict:
Returns the minimum amount of coins needed to make amt"""
# Base case: we've solved this problem already
if amt in solved: return solved.getamt
# Base case: we can make this amount with coin
elif amt in coins:
solved.setdefaultamt
return solved.getamt
solved.setdefaultamt floatinf
# Explore every coin from here, find minimum
for coin in coins:
if coin amt:
nbranch fewestcoinsamtcoin, coins, solved
if nbranch solved.getamt:
solved.popamt
solved.setdefaultamt nbranch
return solved.getamt
L list
L list
n fewestcoins L
n fewestcoins L
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