esign a program that calculates and displays the number of miles per hour over t
ID: 3633614 • Letter: E
Question
esign 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 lease 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
speedlimit = int(raw_input("What is the speed limit? "))
driverspeed = int(raw_input("What is your speed? "))
if 20 <= speedlimit < 70:
if driverspeed < speedlimit:
print "Your not speeding."
else:
milesover = driverspeed - speedlimit
print "Your going ", milesover, " mph over the limit."
else:
print "Error: speed limit not in valid range"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.