Homework 1: Careful Calculations

Assigned
Friday January 22
Due
11 p.m. Wednesday January 27
Summary
In this assignment, you will write two programs using input, output, variables, strings, and numbers. You will reflect on your processes for designing, testing, and debugging the programs.
Collaboration
For this assignment, you will work with a partner of your choice. We will assign partners in class.
Submission
Online turnin form, Wrapper
Warning
So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.

Assignment

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:

  1. Receive a customer request;
  2. Consider what this problem actually involves and how a program will solve it;
  3. Design the code to solve the problem;
  4. Write the code to solve the problem;
  5. Test that the code actually works and debug it if it does not.

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.

In this assignment I would like you to :
  1. Look at the three customer requests below (step #1 in the software development process).
  2. Analyze each request and design an algorithm to solve to the problem. As part of the assignment wrapper, you will write up a paragraph describing your approach to analysis and design for one problem.
  3. After you have studied the problems and designed your algorithms, you should write a program to solve each of the problems.  Please make sure that you write the code in three separate files saved with the names given below.
  4. Once you think you have the code working, TEST it thoroughly.  Don't simply run it once with one set of values and assume it is good.  Test it with three to five different values (or sets of values, actually) and make sure that the numbers the computer gives you agree with the numbers you know to be true or have calculated "by hand". If you find examples that prove your code incorrect, it's your responsibility to fix your solution or report honestly on any problems you discovered but could not fix.  You will write a one paragraph summary of your testing and debugging process and submit this as part of your assignment wrapper.

Notes and requirements:


Customer request #1 (mileage.py)

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.


Customer request #2 (interest.py)

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.


Customer Request #3 (time.py)

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:

He wants you to write a program, 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.


Submitting your work

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.


Janet Davis (davisj@whitman.edu)

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
CC-BY-NC-SA This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.