Can i get some help with this please in python You have been tasked with writing a function called get_demerit_points wh

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Can i get some help with this please in python You have been tasked with writing a function called get_demerit_points wh

Post by answerhappygod »

Can i get some help with this please in python You have been
tasked with writing a function called get_demerit_points which
works out the demerit (penalty) points for a driving speed in a
particular speed limited zone. get_demerit_points has three
parameters: driving_speed speed_limit holiday_period driving_speed
can be either an integer or a float which is the speed the vehicle
was recorded as driving. You can assume the driving_speed is a
positive numeric value. speed_limit is an integer which is the
maximum speed on the stretch of road the driving_speed was
recorded. You can assume the speed_limit is a positive value.
holiday_period is a boolean and is and optional parameter which
defaults to False. The get_demerit_points function does not
validate either the driving_speed or speed_limit values, that is
done by the web application at a later stage. The speed limit can
be any numeric value. The function is not restricted to a
particular set of speed limits. Requirements The specification does
not adhere to the NZ speeding law as the specification was written
from a general perspective and so the specification you see here is
the only requirement to be followed. The function returns the
result as a tuple. The tuple is in the format of Mandatory penalty,
penalty points. If the driver is driving faster than the speed
limit, they are speeding. There are two thresholds which govern if
a penalty will be applied for speeding. One is 4km/h during a
holiday period and any speed more than 4km/h over the speed limit
will result in a mandatory penalty. The other is 5km/h and any
speed more than 5km/h over the speed limit when it is not a holiday
period will result in a mandatory penalty. Mandatory penalty
Mandatory penalty is a boolean. Mandatory penalty has a value of
True if the points must be applied or False if the penalty is
discretionary (may be waived at the discretion of the Police
officer). Mandatory penalty is True if the driving speed exceeds
the speed limit during a holiday period by more than 4km/h.
Mandatory penalty is False if the driving speed does not exceed the
speed limit during a holiday period by more than 4km/h. Mandatory
penalty is True if the driving speed exceeds the speed limit
outside a holiday period by more than 5km/h. Mandatory penalty is
False if the driving speed does not exceed the speed limit outside
a holiday period by more than 5km/h. Penalty points Penalty points
is the number of points that must/could (depending on the value of
Mandatory penalty) be applied. If the driving speed is less than
the speed limit, the function will return 0 penalty points in the
tuple. Mandatory penalty will be False. If the driving speed is the
same as the speed limit, the function will return 0 penalty points
in the tuple. Mandatory penalty will be False. If the driving speed
exceeds the speed limit by no more than 10km/h when driving during
the holiday period, the function will return 10 penalty points in
the tuple. The mandatory penalty is specified in the mandatory
penalty section above. If the driving speed exceeds the speed limit
by more than 10km/h but not more than 20km/h, the function will
return 20 penalty points in the tuple. Mandatory penalty will be
True. If the driving speed exceeds the speed limit by more than
20km/h but not more than 30km/h, the function will return 30
penalty points in the tuple. Mandatory penalty will be True. If the
driving speed exceeds the speed limit by more than 30km/h, the
function will return 50 penalty points in the tuple. Mandatory
penalty will be True. Summary Points might not be applied (it is at
the discretion of the Police officer and so is optional) as there
is a discretionary level of 4km/h in a holiday period and 5km/h
outside a holiday period. Driving speeds above those those
discretionary levels will require a mandatory penalty to be
applied. Hints. Not all of the tests used are shown. As per all the
hidden tests to date, they only test aspects of the above
specification nothing else. Use the test code below and then create
your own test data using that code. Ensure you test every aspect of
the specification. Your first attempt of Moodle checking your code
is free of penalties. The 10% penalties start on the second attempt
and like previous labs applies if the attempt is unsuccessful.
Thoroughly testing your code on the desktop first is advised to
make the most of this. The solution requires less code than lab
3-1-2. Use of good object names and appropriate worded docstring is
required. The solution is about 17-25 lines of code depending on
the approach used. The shorter version uses a loop and some
conditionals and the longer version only uses conditionals. The
longer conditionals only solution is the simpler of the two
approaches and is suggested.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply