Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created January 5, 2021 00:59
Show Gist options
  • Save ZechCodes/7f60d319d490e8a02c7f583fd1f8dec0 to your computer and use it in GitHub Desktop.
Save ZechCodes/7f60d319d490e8a02c7f583fd1f8dec0 to your computer and use it in GitHub Desktop.
Challenge 158 - Time Saved Speeding

Challenge 158 - Time Saved Speeding

One cause for speeding is the desire to shorten the time spent traveling. In long distance trips speeding does save an appreciable amount of time. However, the same cannot be said about short distance trips.

Create a function that calculates the amount of time saved were you traveling with an average speed that is above the speed-limit as compared to traveling with an average speed exactly at the speed-limit.

Examples

# The parameter's format is as follows:
# (speed limit, avg speed, distance traveled at avg speed)

time_saved(80, 90, 40) ➞ 3.3

time_saved(80, 90, 4000) ➞ 333.3

time_saved(80, 100, 40 ) ➞ 6.0

time_saved(80, 100, 10) ➞ 1.5

Notes

  • Speed = distance/time
  • The time returned should be in minutes, not hours.
import unittest
def time_saved(speed_limit: int, average_speed: int, distance: int) -> float:
return 0.0 # Put your code here!!!
class Test(unittest.TestCase):
def test_(self):
self.assertEqual(time_saved(80, 90, 40), 3.3)
def test_1(self):
self.assertEqual(time_saved(80, 90, 4000), 333.3)
def test_2(self):
self.assertEqual(time_saved(80, 100, 40), 6.0)
def test_3(self):
self.assertEqual(time_saved(80, 100, 10), 1.5)
def test_4(self):
self.assertEqual(time_saved(60, 65, 25), 1.9)
def test_5(self):
self.assertEqual(time_saved(60, 60, 20), 0)
def test_6(self):
self.assertEqual(time_saved(80, 95, 200), 23.7)
def test_7(self):
self.assertEqual(time_saved(70, 92, 50), 10.2)
def test_8(self):
self.assertEqual(time_saved(70, 92, 20), 4.1)
def test_9(self):
self.assertEqual(time_saved(70, 100, 12), 3.1)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment