Speeding tickets

To practice using if statements, we are going to make a program to help a police officer calculate the appropriate fine for driving over the speed limit. The cost of the fine will depend on how much the user was speeding by.





Creating your new program

Now you are going to write a simple Python program called speedTicket.py.

Once you are in your lab4 folder, open your file for editing by typing

       emacs speedTicket.py

The first thing you should do in your new file is create and fill out the comment header block at the top of your file. Here is a template (it is text, so feel free to copy and paste it into your file):

# File:        palindrome.py
# Author:      YOUR NAME
# Date:        TODAY'S DATE
# Section:     YOUR SECTION NUMBER
# E-mail:      USERNAME@umbc.edu
# Description: YOUR DESCRIPTION GOES HERE AND HERE
#              YOUR DESCRIPTION CONTINUED SOME MORE
# Collaboration: During lab, collaboration between students is allowed,
#                although I understand I still must understand the material
#                and complete the assignment myself. 





Input

Ask the user to input the speed limit and store it to a variable. (Don't forget to cast it to an integer!)

Also ask the user to input the driving speed, storing it in a variable as well.





Process

You'll then need to calculate by how much the driver was speeding, and print that to the screen for the user.

Using if, elif, and/or else statements, check the amount the driver was speeding by, and print one of these sentences to the screen:





Sample output

Here is a sample run of the program, to give you an idea of what your program could look like. The exact text of the prompts may differ, but the order in which the information is asked for, and the eventual result printed out should be the same as the sample.

User input is shown in blue.

linux2[7]% scl enable python33 bash
bash-4.1$ python speedTicket.py
Please enter the speed limit in MPH: 55
Please enter the driving speed in MPH: 59
You were over the speed limit by 4 MPH.
You receive no ticket... this time.

bash-4.1$ python speedTicket.py
Please enter the speed limit in MPH: 25
Please enter the driving speed in MPH: 45
You were over the speed limit by 20 MPH.
You receive a ticket for a $75 fine.

bash-4.1$ python speedTicket.py
Please enter the speed limit in MPH: 60
Please enter the driving speed in MPH: 90
You were over the speed limit by 30 MPH.
You receive a ticket for a $500 fine, and mandatory court date.
bash-4.1$

Remember to enable Python 3 before running your program!