Associate
- Joined
- 28 Oct 2014
- Posts
- 472
Hi I have the following question to answer in python.
Q) On many major roads average speed checks are in place. Two sensors are placed a known distance apart and vehicle number plate recognition is used to identify a vehicle and the time it enters the section of road being monitored. The time is recorded when the vehicle leaves the monitored section. By using the time taken to travel the known distance, the average speed of a vehicle can be calculated. Create a program for calculating average speeds for a vehicle travelling through a section of road. Output a list of those vehicles exceeding the speed limit set for that section of road.
This is my piece of code but I don't know where I went wrong, would someone be able to help me?
from datetime import datetime
timestart=int(input("Please enter the start time in 24 hours time"))
finishtime=int(input("Please enter end time in 24 hour time"))
name=input("Please enter your name")
timestart=datetime.strptime(timestart, "%H:%M")
finishtime=datetime.strptime(finishtime, "%H:%M")
distance=int(input("Please enter the distance in miles"))
timeanswer=finishtime-timestart
timeanswer2=(timeanswer.seconds/3600)
speed=distance/timeanswer2
speed2=speed
print(speed2,"mph")
if speed>10:
cyclists=open("cyclist.txt","a")
cyclists.write(name)
cyclists.write(" ")
cyclists.write(str(speed2))
cyclists.write("mph\n")
cyclists.close()
Q) On many major roads average speed checks are in place. Two sensors are placed a known distance apart and vehicle number plate recognition is used to identify a vehicle and the time it enters the section of road being monitored. The time is recorded when the vehicle leaves the monitored section. By using the time taken to travel the known distance, the average speed of a vehicle can be calculated. Create a program for calculating average speeds for a vehicle travelling through a section of road. Output a list of those vehicles exceeding the speed limit set for that section of road.
This is my piece of code but I don't know where I went wrong, would someone be able to help me?
from datetime import datetime
timestart=int(input("Please enter the start time in 24 hours time"))
finishtime=int(input("Please enter end time in 24 hour time"))
name=input("Please enter your name")
timestart=datetime.strptime(timestart, "%H:%M")
finishtime=datetime.strptime(finishtime, "%H:%M")
distance=int(input("Please enter the distance in miles"))
timeanswer=finishtime-timestart
timeanswer2=(timeanswer.seconds/3600)
speed=distance/timeanswer2
speed2=speed
print(speed2,"mph")
if speed>10:
cyclists=open("cyclist.txt","a")
cyclists.write(name)
cyclists.write(" ")
cyclists.write(str(speed2))
cyclists.write("mph\n")
cyclists.close()