Cover page images (keyboard)

Lab 06 - Loops


Don Miner & Sue Evans

Hit the space bar for next slide

Step 0














Step 1

For this lab, you are to write a program that will do something that is not algebraically possible. It will find the values of three variables given two equations.

The problem is about a shopping trip to the bookstore. You are to purchase varying quantities of three different school supplies. Pens are $2.71, markers are $3.79, and spiral notebooks are $5.63. You are to buy 15 items total. How many of each item must you purchase to spend a total of exactly $54.05?














Bonus Step

Once you have your program working, you should make it print a simple receipt. If the total had been $57.41, your program would print the following:


linuxserver1.cs.umbc.edu[181] python lab6.py

 8 pens @ 2.71 ea.          21.68
 2 markers @ 3.79 ea.        7.58
 5 notebooks @ 5.63 ea.     28.15
                            -----
                           $57.41

linuxserver1.cs.umbc.edu[182]

You didn't think I was going to show you the sample output of the assigned problem ...

Notice that the output shows the quantities of each item, the individual cost and the total cost for each item. The amounts to be added should be in a column with the decimal points aligned. In short, your output should look exactly like this, except the values will be different for your problem.














Challenge Step

Change your program so that it will ask the user for the number of items to purchase and the total bill. You should provide some output when the total chosen by the user isn't possible.

Your program should use a sentinel loop so that the user can continue to try different numbers of items and totals. What is the obvious sentinel for this problem ?