CMSC 201

Lab 2: A Simple Program

MPG Calculator

To calculate a car's MPG you only need two things:

  1. Distance the car traveled (ex: 250 miles)
  2. Amount of gas used (ex: 10 gallons)

To calculate the mpg divide the distance traveled by the number of gallons used. Using the above numbers that would give us a mpg of 25.

You're going to write a simple program called calculateMPG.py. Open your program by typing

emacs calculateMPG.py &

Next you'll need to get two int variables called

distanceTraveled and gallonsUsed 

from the user (don't forget to cast them into ints!) You'll then use those variables to calculate and assign the car's mpg to a third variable. After that all you need to do is display the mpg and you're done!

The output should looks something like this:

The MPG is: 
25

Don't forget to enable Python 3 by typing

scl enable python33 bash

And then run your program by typing

python calulateMPG.py