NOTE: I do NOT want the answer! I am hoping to get guidance on next steps
Hello everyone!
I am new to python and am working on some homework and have a question about a problem I’m working:
“Define a function consolidate_change that takes as arguments counts of different US coins (similar to the previous function) and prints out the simplest number of bills and coins needed to make that amount. [11pt]
For example, when called with arguments of 10 quarters, 9 dimes, 8 nickels, and 7 pennies, the function should print:
Number of dollars: 3
Number of quarters: 3
Number of dimes: 1
Number of nickels: 0
Number of pennies: 2
Total amount: $3.87
You must use your previous value_of_change() method in this calculation to determine the total amount.”
Now, this is very beginning intro Python, so although I know that there are extremely efficient ways to do this, I am not at the point in our course to use them.
I believe that I can write a modulo function that provides the remainder and then assign the remainder to the next variable, and continue using a modulo function until I have no more remainders. The roadblock I’m having mentally is how to assign the remainder of a modulo to a new variable. Here’s what I have so far, which is very much nothing really at all:
`def consolidate_change(value_of_change):
number_dollars = total_value % 1.00
number_quarters = number_dollars % .25
number_dimes = number_quarters % .10
number_nickles = number_dimes % .05
number_pennies = number_nickles % 0.1`
The value_of_change function referenced above:
`def value_of_change(quarters, dimes, nickels, pennies):
q = .25
d = .10
n = .05
p = .01
total_value = (quarters * q) + (dimes * d) + (nickels * n) + (pennies * p)
return(round(total_value, 2))`
I’m just unsure of where to go. This is a very beginner class, and I’m excited to learn, but it’s also extremely self-directed.
Any thoughts on what to do? I am totally fine with basic directions and then having to write the code myself, but if anyone happens to also have any similar-vein examples so I can visualize the structure of the code, that would be much appreciated also!
Thank you! 🙂
I got stuck on how to take a modulo function and assign the remainder of the function to a new variable.
Gian-Luca Matsuda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.