As usual, create a directory to hold today's files. All programs that you write today should be stored in this directory.
$ cd ~/cs120/labs $ mkdir lab12 $ cd lab12
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.
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.
Function Parameters | Expected Output |
---|---|
0 | 0 |
1 | 1 |
2 | 2 |
5 | 1 |
10 | 1 |
15 | 2 |
16 | 3 |
25 | 1 |
50 | 2 |
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.