Question: In python, In this assignment you will write two functions that are invoked by a main program. You can also write helper functions that aren't
In python,
In this assignment you will write two functions that are invoked by a main program. You can also write helper functions that aren't mentioned here.
Write a function change(amount)that using the parameter value of amount and calculates the monetary equivalent in dollars, quarters, dimes, nickels, and pennies. You can use the following steps to develop the function:
1. Convert the amount from floating point into cents
2. Divide the cents (integer division, //) by 100 to find the number of dollars. Obtain the remaining cents using the cents remainder % 100
3. Divide the remaining cents by 25 (//) to find the number of quarters. Obtain the remaining cents using the cents remainder % 25
4. Divide the remaining cents by 10 (//) to find the number of dimes. Obtain the remaining cents using the cents remainder % 10
5. Divide the remaining cents by 5 (//) to find the number of nickels. Obtain the remaining cents using the cents remainder % 5
6. The remaining cents are pennies.
7. Return a list: [# of dollars, # of quarters, # of dimes, # of nickels, # of pennies]
Write a function stats(mylist) that uses the parameter value of mylist - a sorted list of integers - and calculates the mean, median, and mode of the list, and returns a tuple: (mean, median, and a list of modes). Use the following steps to develop the function:
1) Compute the mean by totaling the list and dividing the total by the number of items in the list.
2) Compute the median of a sorted list:
a) If n is the number of items in the list, and n is odd, the median is the middle item which is at index n // 2. For example, if the list is
[10, 20, 30, 40, 50], n = 5, n // 2 = 2, so the median is 30 - the item at index 2.
b) If n is the number of items in the list and n is even, the median is the mean of the two items in the middle of the list. They occur at
indexes (n - 1) // 2 and ((n - 1) // 2) + 1. For example, if the list is [10, 20, 30, 40, 50, 60], n = 6, then (n - 1) // 2 = 2, and
((n - 1) // 2) + 1 = 3. The items at indexes 2 and 3 are 30 and 40, so the median is (30 + 40) // 2 = 35.
3) Compute the list of modes by determining which items occur the most times. Note - the mode may not be unique. For example, consider the list
[10,20,20,20,30,30,80,80,80,90]. The numbers 20 and 80 each occur three times, so a list of modes is [20,80].
Run you program with the given main program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
