Python programming help needed

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()
 
Associate
OP
Joined
28 Oct 2014
Posts
472
So now this program is all fine and it works:

from datetime import datetime

timestart = input("Please enter the start time in 24 hours time")
finishtime = 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

print("{} mph".format(speed))

if speed > 10:
cyclists = open("cyclist.txt", "a")
cyclists.write(name)
cyclists.write(" ")
cyclists.write(str(speed))
cyclists.write("mph\n")
cyclists.close()

Now I have got another questions which asks for the following:

In the UK most vehicle registrations are in the format: • two letters • two numbers • three letters. For example, AZ01 XYZ. The vehicle number plate recognition system will provide this information as a string of characters. By identifying any vehicle registrations that do not match this pattern, a list of non-standard vehicle registrations and average speeds in excess of the speed limit should be compiled and saved. Create a program for saving a file with these non-standard registrations for those vehicles exceeding the speed limit set for that section of road.

So I would use code from the first question but I don't know how to do the number plate part. So how to do that it will record the non-standard number plates?
 
Back
Top Bottom