Your book spends a lot of time talking about problem solving. Let's look at how this would work, at least for some small problems (because you don't know enough to tackle big problems yet).
For small problems like we will be working with in this assignment, this process means that you:
Note that these steps are iterative. As long as your program has
bugs, you may need to rewrite your code, reconsider your design,
reconsider the problem, or ask more questions about what the customer
wants.
Notes and requirements:
You are contacted by Tracy Peterson who is the administrative assistant for Whitman College's Physical Plant. She is responsible for keeping track of gas mileage for the vehicles in the college motor pool. She wants a tool to help her calculate miles per gallon (MPG).
To compute MPG, you record the starting and ending mileage of the car, subtract to find the total mileage driven, and then divide this by the amount of gas consumed. For example, Sarah Duisburg wrote: "On a past trip to visit my family, my car's odometer was at 92567 when I left and 92783 when I returned. When I refilled the gas tank, it required 10.6 gallons of gas. This comes out to 20.377 miles per gallon (my last car got really bad mileage)."
Ms. Peterson asks you to write a program,mileage.py
,
that
prompts her for a car's starting and ending mileage, as well as the
gallons
of gasoline consumed. It then calculates the MPG and prints a
message reporting the MPG of the car.
Note: Your program should ask for the starting mileage first, the ending mileage second, and the total gasoline consumed last. Failure to following this ordering will result in some point deduction.
You are contacted by Dr. Jan Crouter who is the chair of the
Economics department at Whitman College. Her department is searching
for a new professor of finance. The new professor will need a general
tool that their students can use to compute compound interest.
Dr. Crouter tells you the program should take the following inputs from the user:
The program should calculate and print the final amount of the
investment, with interest, after the specified number of years have
elapsed.
Note: Your program should ask for the inputs in the order specified. Failure to following this ordering will result in some point deduction.
Hint: The formula for
computing compound interest is given in chapter 2, problem 5. You may
have already written a solution for a special case of this problem when
you worked through the chapter 2 exercises.
You are contacted by Dr. Wally Herbranson who teaches psychology at Whitman College. In his research on comparative cognition, he and his students use a computer to time tasks that pigeons learn how to do. Computers measure time in milliseconds, but some tasks, such as the box and banana problem, take longer than a minute to complete.
Dr. Herbranson wants a tool that converts time in milliseconds into time in minutes, seconds, and milliseconds. Remember that:
time.py
, that prompts
the
user for the number of milliseconds. It then breaks the number of
milliseconds down into minutes, seconds, and milliseconds and prints
out these numbers. For example,
an input of 62,523 milliseconds should give an output of 1 minute, 2
seconds, and 523
milliseconds, or 1:02.523.Note: Your program should provide output values in the order specified above. Failure to follow this ordering will result in some point deduction.
Hint: Work backwards. The integer division and the modulus operator will help a lot.
Make sure your files are named correctly as specified above. In your comments at the top, make sure you:
Submit all three files using the online turnin form. Be sure to select Homework 1.
Individually complete the assignment Wrapper on Google Forms.
This assignment is adapted from one developed by Sarah Diesburg and
shared through EngageCSEdu. Thanks to Albert Schueller for the "Above
& Beyond"
policy. Thanks to Tracy Peterson, Jan Crouter, and Wally Herbranson, for humoring me.
Created January 20, 2016
Last revisedJanuary 24, 2016, 12:16:41 PM PST
This work is licensed under a Creative
Commons Attribution-Noncommercial-Share Alike 3.0 United States License.