Skip to content

Commit add8cf9

Browse files
committed
feat(141 day): calculate additional whole gallons needed for takeoff fuel based on liter requirements
1 parent d557dc7 commit add8cf9

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
3+
Takeoff Fuel
4+
Given the numbers of gallons of fuel currently in your airplane, and the required number of liters of fuel to reach your destination, determine how many additional gallons of fuel you should add.
5+
6+
1 gallon equals 3.78541 liters.
7+
If the airplane already has enough fuel, return 0.
8+
You can only add whole gallons.
9+
Do not include decimals in the return number.
10+
"""
11+
12+
import unittest
13+
14+
class TakeOffFuelTest(unittest.TestCase):
15+
16+
def test1(self):
17+
self.assertEqual(fuel_to_add(0,1), 1)
18+
19+
def test2(self):
20+
self.assertEqual(fuel_to_add(5, 40), 6)
21+
22+
def test3(self):
23+
self.assertEqual(fuel_to_add(10, 30), 0)
24+
25+
def test4(self):
26+
self.assertEqual(fuel_to_add(896, 20500), 4520)
27+
28+
def test5(self):
29+
self.assertEqual(fuel_to_add(1000,50000), 12209)
30+
31+
import math
32+
def fuel_to_add(current_gallons, required_liters):
33+
34+
# Converting current gallons to liters
35+
36+
current_liters = current_gallons * 3.78541
37+
38+
# If already enough fuel, return 0
39+
40+
if current_liters >= required_liters:
41+
return 0
42+
43+
needed_liters = required_liters - current_liters
44+
45+
needed_gallons = needed_liters / 3.78541
46+
47+
return math.ceil(needed_gallons)
48+
49+
50+
51+
if __name__ == "__main__":
52+
print(fuel_to_add(10, 50))
53+
unittest.main()

0 commit comments

Comments
 (0)