Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are charged $6 per a mph over the speed limit, $7 per a mph over the speed limit when in a school or work

You are charged $6 per a mph over the speed limit, $7 per a mph over the speed limit when in a school or work zone, or $8 per a mph over the speed limit when driving in a residential area with an additional $200. If you drive 20mph or higher over the speed limit, regardless of what type of road, this is considered reckless driving for which you should follow the first offense rule of a total of $350 fine regardless how many mph you go over the speed limit. You can also be fined for driving too slowly. We will just assume a fine of $30 for all speeds below the speed limit.

Additionally, demerit points are given for a traffic offense based on a case-by-base severity. We will assume that being over the speed limit by 1-9mph earns 3 demerit points, 10-19mph earns 4 demerit points, and 20mph and over earns 6 demerit points.

Using the information above, write a file with two functions: fine and demerits. fine should take in 3 parameters and return the fine in dollars that the individual caught speeding would have to pay based on those parameters. demerits should take in 2 parameters and return the number of demerit points that the driver would earn based on the parameters.

Neither function should print anything nor ask for any input. You should not submit any code outside of these two functions.

You can also assume that we will not provide any negative numbers for speed_limit and my_speed below.

fine(speed_limit, my_speed, zone)

The speed_limit is a number that indicates the posted speed limit.

The my_speed is a number that indicates the speed that the individual was actually traveling at.

The zone is an optional string that indicates what zone the individual is driving in; if not present, it should default to None. If present, it can only be one of the three following words: school, work, or residential.

The correct behavior of this function is to return the fine that the individual will be ticketed with.

demerits(speed_limit, my_speed)

The speed_limit is a number that indicates the speed limit that should be driven. The my_speed is a number that indicates the speed that the individual was actually

traveling at. The behavior of this function is to return the number of demerit points earned.

In addition to functional correctness, make sure have good variable names and have meaningful docstrings for all functions written.

Example Invocations

When you run the file, nothing should happen. It defines functions, it does not run them. If in another file, you write the following:

import fines

print("$", fines.fine(50, 20)) print("$", fines.fine(50, 75)) print("$", fines.fine(25, 30, "work"))

print("$", fines.fine(25, 35, "residential"))

print() print(fines.demerits(75, 50), "demerit points")

print(fines.demerits(50, 65), "demerit points")

print(fines.demerits(50, 75), "demerit points")

you should get the following output:

$ 30 $ 350 $ 35 $ 280 0 demerit points 4 demerit points 6 demerit points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions