Exercise 4 – Chapter 7 Speeding violation Calculator Python code for the followi
ID: 3633403 • Letter: E
Question
Exercise 4 – Chapter 7 Speeding violation CalculatorPython code for the following
Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speed limit and the driver’s speed. Validate the input as follows:
• The speed limit should be at least 20, but not greater than 70.
• The driver’s speed should be at least the value entered for the speed limit (otherwise the driver was not speeding).
Once correct data has been entered, the program should calculate and display the number of miles per hour over the speed limit that the driver was doing.
Explanation / Answer
def checklimit(): actual = input("Enter the offender's speed in mph: ") limit = input("Enter the speed limit in mph: ") if (limit > 20) and (limit < 70): if actual > limit: print "Driver was going", actual-limit, "mph over the limit." else: print "Driver was going at a legal speed." else: print 'Invalid speed limit.'Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.