CS 141 - Fall 2019

Program 2: Scooter Rentals

Assigned: Friday, September 6
Due: Thursday, September 12, 2019 by 11:55pm (on Moodle)

Description

The City of Memphis offers a number of options for electric scooter rentals. As an avid rider, you're always trying to determine the most cost-effective option for your scooter riding needs. Each option requires that the user knows about how long they will be using the scooter. Since it is easier for users to look up the distance they need to travel, the user will enter the total distance of their trip and you will calculate the total time it will take (assume an average pace of 15 mph). Using the following cost schemes, calculate the total cost of the ride for each company and tell the user which company they should use.

Company A: $1 + $0.15/minute of use
Company B: $2.50 for the first 5 minutes + $0.12/minute for every minute after
Company C: $5 + $0.06/minute of use

What you need to do

Your program when completed, should do the following:
  • Ask the user whether they want to type in the distance in miles or kilometers. The user should be able to enter either "k" or "K" for kilometers, and either "m" or "M" for miles. They only need to type the single letter. You may allow the user to type the whole word if you so desire.
  • Print out the distance using the opposite units (so the user can see the distance in both miles and kilometers).
  • Calculate the total time of the trip, based on distance, assuming an average pace of 15 miles per hour.
  • Output the total time of the trip.
  • Calculate the total cost of the trip using each company.
  • Output which company and the cost of the trip for the cheapest option.
  • For full credit, you must correctly print out the cost with a $ and rounded properly to 2 decimal places.

    Guidelines

  • Follow the instructions for commenting your code.
  • Use the following to convert back and forth between miles and kilometers: one mile = 1.60934 kilometers.
  • Use a series of if-elif-else tests to determine which Company is the best (cheapest) option.
  • You must define a main() function for your program. You do not need to use any other functions unless you so desire. (The primary point of this program is to test your if/else skills; there will be other programs later to test your function skills.)
  • Test your program on lots of examples, including the sample ones below, and make sure they work correctly. Your program should work correctly for all reasonable inputs, not just the sample ones below.

    What to Do

  • Create a Python program named yourlastname_yourfirstname_prg2.py
  • Submit your Python file on Moodle under Program 2.
  • Sample Interactions

    What the computer displays (prints) is in regular text, what the user types is in bold, and what the program is doing behind the scenes is in italics.

    	

    Test 1

    (Program begins) Do you want to enter distance as miles or kilometers (type m or k): m How many miles would you like to scooter? 10 That is 16.0934 kilometers. Total time in minutes: 40.0 You should use Company B. It will cost $6.70. (Program ends)

    Test 2

    (Program begins) Do you want to enter distance as miles or kilometers (type m or k): k How many kilometers would you like to scooter? 7.5 That is 4.6602955248735505 miles. Total time in minutes: 18.641182099494202 You should use Company A. It will cost $3.80. (Program ends)

    Test 3

    (Program begins) Do you want to enter distance as miles or kilometers (type m or k): M How many miles would you like to scooter? 15.8 That is 25.427572 kilometers. Total time in minutes: 63.20000000000001 You should use Company C. It will cost $8.79. (Program ends)
    Your code does not need to follow this script verbatim, but all the mentioned functionality should work as shown.

    Grading

    Your program will be graded on correctness, as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation, and comments (this is not an exhaustive list). See the syllabus for further grading details.

    You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.