Question

How to write a program in python for "speed violation calculator" with a while loop and...

How to write a program in python for "speed violation calculator" with a while loop and if statements.

calculate the number of miles over the speed limit and display it.

ask for the speed limit and the drivers speed

the speed limit should be at least 20 but not greater than 70

if the driver's speed is less then the speed limit the driver was not speeding

program should calculator and display the number of mph over the speed limit that the driver was doing

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Input speed limit
speedLimit = int(input('Enter speed limit: '))
# Validate if speed limit entered is in valid range or not
while speedLimit < 20 or speedLimit > 70:
    print('Invalid speed limit. Try again.')
    speedLimit = int(input('Enter speed limit: '))
    
# Input driver's speed
driverSpeed = int(input('Enter driver\'s speed: '))

#Check if driver is speeding or not
if driverSpeed <= speedLimit:
    print('Driver is not speeding')
else:
    print('Driver is speeding ' + str(driverSpeed - speedLimit) + ' mph over the speed limit')

SAMPLE OUTPUT:

Add a comment
Know the answer?
Add Answer to:
How to write a program in python for "speed violation calculator" with a while loop and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python "Speeding Violation Calculator" Program

    Please create this program in Python and run it making sure it works... Thank you SO much in advance. :)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 speedlimit 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...

  • Chapter 7 exercise 4, python code for Speeding violation Cal

    Exercise 4 – Chapter 7 Speeding violation CalculatorPython code for the followingDesign 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 speedlimit 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...

  • Speeding Violation Calculator: Design a program that calculates and displays the number of miles per hour...

    Speeding Violation Calculator: 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...

  • Write a program that calculates the calories burned while running over a given number of miles....

    Write a program that calculates the calories burned while running over a given number of miles. While several factors determine how many calories are burned during a mile run, for this program, 90 calories are burned for every mile of running. The cumulative calories burned during a run can be calculated as: Calories * Distance For example, if a person runs 5 miles, the total calories burned is 450. After 3 hours, the person has burned 2 calories. The program...

  • The distance a vehicle travels can be  calculated as follows: distance = speed * time. For...

    The distance a vehicle travels can be  calculated as follows: distance = speed * time. For example, if a train travels 40 miles per hour for three hours, the distance traveled is 120 miles. Write a program using python that asks the user for the speed of a vehicle in mph and the number of hours it has traveled. It should then use a while loop to display the distance the vehicle has traveled for each hour of that time...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

  • Write a python program that uses a while loop to print numbers 100,98,96... all the way...

    Write a python program that uses a while loop to print numbers 100,98,96... all the way to 0. each number should be printed on a seperate line

  • Speeding Fine Calculator You have been hired by the police department of the city you live...

    Speeding Fine Calculator You have been hired by the police department of the city you live in to create a program to calculate the fine that a motorist could pay. If the motorist was travelling at or below the speed limit, there is no fine. If the motorist is travelling over the speed limit, the amount of the fine is determined based on the table below. The speed limit that will be entered is a multiple of 5 from 5...

  • Create a Python program that asks the user how many miles they think they may run....

    Create a Python program that asks the user how many miles they think they may run. The program should also ask them how much they weight. The program should then use a loop to calculate and print the number of calories burnt while running each mile. o Assume that a person burns 1 calorie per pound during each mile of running

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT