Write a function called
multiply_integers(a, b)
, which
takes two integers as parameters. Your
function should return the result of
multiplying the integers a and b
together.
Write a function called
average_four(value1, value2, value3,
value4)
, which takes 4 floating point
values as parameters. Your function should
return the arithmetic mean (standard
average) of the four values.
There are many people that would call me a lazy person. I don't find that offensive, but I think it's not a valid description. It's not that I'm lazy, I just try to be as efficient as possible. For example, in college a group of friends and I deduced the fewest amount of coins to carry that would produce any arbitrary amount of change. While a computation like that is still a little too complex, figuring out the fewest amount of coins for a fixed amount of change is possible.
Details
Create the function count_coins(cents)
in a file
called change.py. This function should take as a parameter
the number of cents (an integer in the range 0 to 100) and returns
the smallest number of coins (using the American monetary system
consisting of quarters, dimes, nickles and pennies) necessary to
make that amount of change.
Test your function by calling the function multiple times with different parameters. Make sure your code follows the course's code conventions.
Test Cases
Function Parameters | Expected Output |
---|---|
0 | 0 |
1 | 1 |
2 | 2 |
5 | 1 |
10 | 1 |
15 | 2 |
16 | 3 |
25 | 1 |
50 | 2 |
Hint
- While it might seem like you are going to use a loop for this function, you actually won't use a single loop.
- You can use integer division (//) to determine how many times a coin goes into the change amount evenly.
- Recall that you can use the mod (%) operator to determine the remainder of an integer division operator. Use this to determine the change amount the rest of the coins need to cover.
- Start with the largest coin first (quarters) and work your way down. This is known as a greedy approach, and is very common in Computer Science.
Challenge
Going back to my inspiration for this activity, the perfect amount
of change is going to be the maximum number that this function
will produce on inputs in the range [0,
100). Once your function is written and tested well,
compute the number of coins for all possible change values. Use
the max
function to find the largest number of coins.
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.