Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- done = "n"#enter the distance, used a while and try/excpet to allow people to make mistakes.
- while done == "n":
- try:
- distance_miles = int(input("enter the distance between the two cameras, in miles: "))
- done = "y"
- except:
- print("it must be an integer in miles, try again")
- done = "n"
- speedlimit = 70#defines the speedlimit
- speeders = []#defines the list of speeders for later.
- while True:#menu, allows the user to choose one of two options. option 1 being the main bit of program, option 2 allowing the user to quit.
- option = input("option 1: monitor the speed of a vehicle.\noption 2: out the list of vheicles breaking the speed limit and quit the program.\nenter number of option: ")
- if option == "1":
- try:
- car_plate = input("enter the car number plate _")
- car_point1 = input("enter the time the car passes the first camera\nusing the format HH:MM:SS _")#enters the time, and then the next lines processs it.
- time1 = car_point1.split(":")
- time1hour = int(time1[0])
- time1mins = int(time1[1])
- time1secs = int(time1[2])
- time_in_hours1 = (time1hour+(time1mins/60)+(time1secs/60)/60)
- car_point2 = input("enter the time the car passes the second camera\nusing the format HH:MM:SS _")#second time. could have used a loop or function to reduce line count, but not significanlty.
- time2 = car_point2.split(":")
- time2hour = int(time2[0])
- time2mins = int(time2[1])
- time2secs = int(time2[2])
- time_in_hours2 = (time2hour+(time2mins/60)+(time2secs/60)/60)
- timetaken = time_in_hours2 - time_in_hours1#finds the differeence between the two tines, so the time taken.
- speed = distance_miles/timetaken
- print("speed is:",speed,"mph")
- if speed > speedlimit:#evaluate if the car is speeding or not.
- print("this car is speedng")#output
- speeders.append(car_plate)
- print("The current list of speeders is:",speeders)#output of list of speeders
- else:
- print("this car is not speeding")#output
- except:
- print("you have not entered the time in the right format, try again")
- elif option == "2":
- print("The list of speeders is:",speeders)#output of list of speeders
- print("goodbye")
- break#quit
- else:
- print("that is not an option")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement