| CPSC 115L: Introduction to Computing | Spring 2010 |
Note. To print text with apostrophes, use double quotations; for example,Welcome to Alyssa's Coffee! Enter today's price for one pound: 9.95 How many pounds for this order? 6 With 9.95 dollars a pound, the total for 6 pounds is 65.7 dollars.
As before, first write down on a piece of paper your I/O specification and algorithm in pseudocode. Then implement your algorithm in a Python script named coffee1.py. Run your script with five test cases, and save the snapshots of your test runs in a text file named coffee1.out. As done in laboratories, put a file header at the top of each file.print "Welcome to Alyssa's Coffee!"
Implement your function and write a code segment to invoke it in a Python script named coffee2.py. Run your script with five test cases, and save the snapshots of your test runs in a text file named coffee2.out. Put a file header at the top of each file. When completed, show your work to the instructor or TA.Welcome to Alyssa's Coffee! Enter today's price for one pound: 9.95 How many pounds for the first order? 6 With 9.95 dollars a pound, the total for 6 pounds is 65.7 dollars. How many pounds for the second order? 2 With 9.95 dollars a pound, the total for 2 pounds is 22.9 dollars. How many pounds for the third order? 3 With 9.95 dollars a pound, the total for 3 pounds is 33.6 dollars.
Alyssa's Coffee wants to have a price list showing the price of multiple pounds of coffee. For example, here's the price list for up to 10 pounds of coffee at 9.95 per pound:
Price List for Bulk Purchases at 9.95 dollars per pound Pounds Cost With 5% Discount 1 12.2 11.7 2 22.9 21.9 3 33.6 32.11 4 44.3 42.31 5 55.0 52.51 6 65.7 62.72 7 76.4 72.92 8 87.1 83.12 9 97.8 93.32 10 108.5 103.53
Write a function named print_price_list() that takes two parameters, the price per pound, and n, for number of pounds, and prints a 3-column price list that includes number of pounds in column 1, total cost in column 2, and cost with a 5% discount per pound in column three. The function should print a price list with n rows. Don't forget the overhead, which applies to the whole order.
Note, to get columns aligned, you can print a tab character ('\t'). Also, to round your price to two decimal places use the Python round(x, n), which rounds x to n decimal places.
|
|
CPSC 115L home page |
|
|