My aim is to create code that can verify inputted number plates and verify them to the format: AA/11/AAA 2 letter, 2 numbers, 3 letters. If the entered plate is incorrect, it is saved to a file called 'invalidplates' which shows an array of all of the number plates that exceed the desired speed limit.
Here are the questions
a) 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.
b)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.
c) The authorities have a file of known vehicle registrations and the vehicle’s owner. Those vehicles with standard registrations can be looked up in this file and a fine automatically sent out. A new file is created by comparing the information from the average speed recording system with the file of registered vehicles and their owners’ details. This new file should include the owner’s name and address details, the registration of the vehicle and the average speed of the vehicle in the section of road. Create a program for creating a file of details for vehicles exceeding the speed limit set for a section of road. You will need to create a suitable file with test data, including standard registrations and vehicle owner information.
Here is my code:
file = open("Speeders.txt", "w")
import random, string, time
Speeders = [] #Array
while True:
try:
Distance = float(input("Enter a known distance.(Metres ONLY)"))
break
except ValueError: #Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
while True:
try:
TimeTaken = float(input("Enter the time taken to pass the distance"))
break
except ValueError:#Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
while True:
try:
Limit = int(input("Enter the speed limit in metres per second"))
break
except ValueError:#Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
Speed = (Distance) / (TimeTaken)
print (("The speed of the vehicle was " + str(Speed) + " metres per second"))
while True:
try:
if (Speed) > (Limit):
def NumPlate(self):
plateFormat = ['L', 'L', 'N', 'N', 'L', 'L', 'L']
NumPlate = []
for i in plateFormat:
if i == 'L':
NumPlate.append(random.choice(string.ascii_letters[26:]))
elif i == 'N':
NumPlate.append(str(random.randint(0, 9)))
NumPlate.insert(4, " ")
NumPlate = str(input("Enter the vehicle's number plate."))
Speeders.append (NumPlate)
return "".join(NumPlate)
break
while True:
reply = input('Enter Y to add another number plate N to print list: ')
if reply == "Y":
while True:
try:
Distance = float(input("Enter a known distance.(Metres ONLY)"))
break
except ValueError: #Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
while True:
try:
TimeTaken = float(input("Enter the time taken to pass the distance"))
break
except ValueError:#Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
while True:
try:
Limit = int(input("Enter the speed limit in metres per second"))
break
except ValueError:#Allows ONLY numbers to be inputted, anything else is rejected
print ("Invalid input (Numbers ONLY)")
Speed = (Distance) / (TimeTaken)
print (("The speed of the vehicle was " + str(Speed) + " metres per second"))
if (Speed) > (Limit):
NumPlate = str(input("Enter the vehicle's number plate."))
Speeders.append (NumPlate)
while True:
reply = input('Enter Y to add another number plate N to print list: ')
file.write("Here is a list of the Speeders' number plates on the roads\n")
file.write("List" + str(Speeders))
if reply == "N":
for i in Speeders:
print("This is the list of current number plates that are speeding: " + str(Speeders))
Any help to improve/fix my code will be greatly appreciated :)