Themadhatter1999

trip calculator

May 26th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #improvements are better. This will be on pastebin.
  2.  
  3. #this is a mini-program for calculating distance, time it takes to get to a place and how fast a car was traveling given a certain distance and time it took to get there.
  4.  
  5. #A library that contains the functions and classes uaed here
  6. import vehiclelib
  7.  
  8. option = 0
  9. mph = 0
  10. time = 0
  11. distance = 0
  12.  
  13. #loop with a sintanel value given as the letter q to stop the program
  14. while option != 'q':
  15.     print('type q to quit the program.')
  16.     try:
  17.         option = input(' 1. find the speed of a vehicle.\n 2. find the distance a vehicle traveled.\n 3. find the time it will take to get some distance \n')
  18.     #if option is 1 prompt for distance and time then call calcSpeed to get the speed of the object
  19.         if option == '1':  
  20.             distance = float(input('enter the distance: '))
  21.             time = float(input('enter the time it would or did take to get there in hours: '))
  22.             mph = int(vehiclelib.calcSpeed(distance, time))
  23.     #give result to user
  24.             print('your speed is: '+str(mph)+ 'mph \n')
  25.     #if option 2 prompt for speed of the object and the time the object has been traveling for
  26.         elif option == '2':
  27.             speed = float(input('enter the speed: '))
  28.             time = float(input('enter the time it took or takes to get there: '))
  29.     #call calcDistance function ans return the result
  30.             distance = int(vehiclelib.calcDistance(speed, time))
  31.     #output distance traveled
  32.             print('the distance you could have traveled in that time is: ' +        str(distance) +' miles\n')
  33.     #option three will take input as a floating point value and calculate the time ot takes to travel some place
  34.         elif option == '3':
  35.             distance = float(input('enter a distance you are going to or already have traveled: '))
  36.             speed = float(input('enter the speed of the vehicle here: '))
  37.             #call calcTime to calculate t = distance/speed return result
  38.             time = int(vehiclelib.calcTime(distance, speed))
  39.             print('The time it would have taken to get there is: ' + str(time) +' hours \n')
  40.             break
  41.     except ValueError:
  42.                 print('only type a number!')
  43.    
Advertisement
Add Comment
Please, Sign In to add comment