Question
Make a Python Algorithm: Describe the second part of making change. According to one method, the first step is to compute the difference between the
Make a Python Algorithm: Describe the second part of making change.
According to one method, the first step is to compute the difference between the purchase price and the amount of money that the customer gives the merchant. The result of this calculation is the total amount that the merchant must return to the purchaser. For example, if you buy a dozen eggs at the farmers market for $2.39 and you give the farmer a $10 bill, she should return $7.61 to you. To produce this amount, the merchant selects the appropriate coins and bills that, when added to $2.39, make $10.00.
According to another method, the merchant starts with the purchase price and goes toward the amount given. First, coins are selected to bring the price to the next dollar amount (in this case, $0.615 3 dimes, 1 nickel, and 4 pennies), then dollars are selected to bring the price to the next 5-dollar amount (in this case, $2), and then, in this case, a $5 bill completes the transaction. As you will see in this book, there can be many possible methods or algorithms that solve the same problem, and the choice of the best one is a skill you will acquire with practice.
Few people can subtract three-digit numbers without resorting to some manual aids, such as pencil and paper. As you learned in grade school, you can carry out subtraction with pencil and paper by following a sequence of well-defined steps. You have probably done this many times but never made a list of the specific steps involved. Making such lists to solve problems is something computer scientists do all the time. For example, the following list of steps describes the process of subtracting two numbers using a pencil and paper:
Step 1 Write down the two numbers, with the larger number above the smaller number and their digits aligned in columns from the right.
Step 2 Assume that you will start with the rightmost column of digits and work your way left through the various columns.
Step 3 Write down the difference between the two digits in the current column of digits, borrowing a 1 from the top numbers next column to the left if necessary.
Step 4 If there is no next column to the left, stop. Otherwise, move to the next column to the left, and go back to Step 3.
Write an algorithm that describes the second part of the process of making change (counting out the coins and bills).
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