## Homework 2: Simple Loops

Subject: PSU/CS CGI Programming

 CS161 Introduction to Programming and Problem Solving Winter 2013 Due January 24, 2013

Exercise 2 is intended to introduce you to developing simple algorithms. This will include looping and decision making.

Jasper and Casper are off on a road trip across the country. They’d like you to write a Python program to check their fuel efficiency (miles per gallon). They are starting their trip with a full tank of gas and 10,000 miles on the odometer.

Your program will behave as follows:

(1)   The program will prompt the user for the name of the city where they filled their fuel tank. The user will respond by entering the name of the city.

(2)   The program will prompt the user for the mileage shown on their car’s odometer. The user will respond by entering their mileage in integer format (i.e., no tenth’s of miles);

(3)   The program will prompt the user to enter the number of whole gallons of fuel required to fill the gas tank. The user will respond by entering the number of gallons in integer format (i.e., no tenths of a gallon).

(4)   The program will display the message (where d represents a digit, and you can show as many digits before and after the decimal as necessary):

MPG: d.d

(5)   The program will return to Step 1 and continue prompting and accepting this information from the user and display the MPG between two fill ups until the user enters “ALL DONE” (two words separated by one space, all upper case) in response to being prompted for the name of the city.

(6)   Once the user has entered “ALL DONE” the program will display the message:

Overall MPG: d.d

Submission Instructions

Save your Python file under the name hw2_LastName-FirstName.py and submit it using the moodle.

Make sure that your program only includes the prompts shown above (one for the name of the city, one for the mileage and one for the amount of fuel) for each fill up, displays the miles per gallon for that fill up immediately after the user enters these three items, and displays the overall MPG after the user enters “ALL DONE.”

Hints:

• Keep track of total miles traveled and total gallons of fuel used for your overall MPG calculation
• You need to remember what the mileage was when you last filled up, so you can determine how far you’ve gone on this leg of the trip