Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. done = "n"#enter the distance, used a while and try/excpet to allow people to make mistakes.
  2. while done == "n":
  3.     try:
  4.         distance_miles = int(input("enter the distance between the two cameras, in miles: "))
  5.         done = "y"
  6.     except:
  7.         print("it must be an integer in miles, try again")
  8.         done = "n"
  9. speedlimit = 70#defines the speedlimit
  10. speeders = []#defines the list of speeders for later.
  11. 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.
  12.     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: ")
  13.     if option == "1":
  14.         try:
  15.             car_plate = input("enter the car number plate _")
  16.             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.
  17.             time1 = car_point1.split(":")
  18.             time1hour = int(time1[0])
  19.             time1mins = int(time1[1])
  20.             time1secs = int(time1[2])
  21.             time_in_hours1 = (time1hour+(time1mins/60)+(time1secs/60)/60)
  22.             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.
  23.             time2 = car_point2.split(":")
  24.             time2hour = int(time2[0])
  25.             time2mins = int(time2[1])
  26.             time2secs = int(time2[2])
  27.             time_in_hours2 = (time2hour+(time2mins/60)+(time2secs/60)/60)
  28.             timetaken = time_in_hours2 - time_in_hours1#finds the differeence between the two tines, so the time taken.
  29.             speed = distance_miles/timetaken
  30.             print("speed is:",speed,"mph")
  31.             if speed > speedlimit:#evaluate if the car is speeding or not.
  32.                 print("this car is speedng")#output
  33.                 speeders.append(car_plate)
  34.                 print("The current list of speeders is:",speeders)#output of list of speeders
  35.             else:
  36.                 print("this car is not speeding")#output
  37.         except:
  38.             print("you have not entered the time in the right format, try again")
  39.     elif option == "2":
  40.         print("The list of speeders is:",speeders)#output of list of speeders
  41.         print("goodbye")
  42.         break#quit
  43.     else:
  44.         print("that is not an option")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement