Question: Using Python 2.7 Consider the following scenario: You might have been driving a little too fast when a police officer stops you. Write code to
Using Python 2.7
Consider the following scenario: You might have been driving a little too fast when a police officer stops you. Write code to determine the type of ticket you are to receive and the charge of the ticket. The requirements are as follows: Define a function called: police
The function should receive 2 arguments: speed, bday
speed should receive the speed of the vehicle from the police officers perspective
bday should be a Boolean as to whether it is your birthday or not (true or false)
If speed is 60 or less, the result is a warning ticket. If speed is between 61 and 80 inclusive, the result is a speeding ticket.
If speed is 81 or more, the result is an excessive speeding ticket.
Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.
Speed < 0 should provide the message 'Speed can not be negative.' Speed >= 150 should provide the message ''Where's the fire! You're going downtown, Flash!''
For speeding tickets, for every mile an hour over the speed limit, a $10 charge is given.
For excessive speeding tickets, for every mile an hour over the speed limit, a $15 charge is given. The output statement should be from one print statement.
Below is an example of how the output should be retune and in what format:
>>> police(70, True) You are rewarded with a(n) speeding ticket.
The charge is $50.00 Have a great day!
You should be able to type in any number and it should return what kind of ticket you have, the amount of the charge, and "have a great day!". exactly like the example.
Here are some examples of what it should return.
>>> police(86, True) You are rewarded with a(n) excessive speeding ticket. The charge is $315.00 Have a great day! >>> police(81, False) You are rewarded with a(n) excessive speeding ticket. The charge is $315.00 Have a great day!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
