Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #improvements are better. This will be on pastebin.
- #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.
- #A library that contains the functions and classes uaed here
- import vehiclelib
- option = 0
- mph = 0
- time = 0
- distance = 0
- #loop with a sintanel value given as the letter q to stop the program
- while option != 'q':
- print('type q to quit the program.')
- try:
- 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')
- #if option is 1 prompt for distance and time then call calcSpeed to get the speed of the object
- if option == '1':
- distance = float(input('enter the distance: '))
- time = float(input('enter the time it would or did take to get there in hours: '))
- mph = int(vehiclelib.calcSpeed(distance, time))
- #give result to user
- print('your speed is: '+str(mph)+ 'mph \n')
- #if option 2 prompt for speed of the object and the time the object has been traveling for
- elif option == '2':
- speed = float(input('enter the speed: '))
- time = float(input('enter the time it took or takes to get there: '))
- #call calcDistance function ans return the result
- distance = int(vehiclelib.calcDistance(speed, time))
- #output distance traveled
- print('the distance you could have traveled in that time is: ' + str(distance) +' miles\n')
- #option three will take input as a floating point value and calculate the time ot takes to travel some place
- elif option == '3':
- distance = float(input('enter a distance you are going to or already have traveled: '))
- speed = float(input('enter the speed of the vehicle here: '))
- #call calcTime to calculate t = distance/speed return result
- time = int(vehiclelib.calcTime(distance, speed))
- print('The time it would have taken to get there is: ' + str(time) +' hours \n')
- break
- except ValueError:
- print('only type a number!')
Advertisement
Add Comment
Please, Sign In to add comment