CoCalc Public FilesClass Samples / calculate-drive-time.pyOpen with one click!
Authors: Barry Bandstra, Ryan McFall
Compute Environment: Ubuntu 20.04 (Default)
1
distance_to_travel = float(input('How far are you going? '))
2
speed_limit = float(input('What is the speed limit? '))
3
minutes_to_save = float(input('How many minutes do you want to save? '))
4
5
numerator = (speed_limit * minutes_to_save * speed_limit) / (distance_to_travel * 60)
6
denominator = 1 - (speed_limit * minutes_to_save) / (distance_to_travel * 60)
7
8
new_speed = (numerator / denominator) + speed_limit
9
10
print ('You should go', new_speed, 'to save', minutes_to_save, 'minutes over going', speed_limit, end=' ')
11
print ('when traveling', distance_to_travel, 'miles')
12