Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69272dcf1c24b44fd79137c4 Challenge 141: Takeoff Fuel 29 challenge-141

--description--

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.

  • 1 gallon equals 3.78541 liters.
  • If the airplane already has enough fuel, return 0.
  • You can only add whole gallons.
  • Do not include decimals in the return number.

--hints--

fuel_to_add(0, 1) should return 1.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fuel_to_add(0, 1), 1)`)
}})

fuel_to_add(5, 40) should return 6.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fuel_to_add(5, 40), 6)`)
}})

fuel_to_add(10, 30) should return 0.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fuel_to_add(10, 30), 0)`)
}})

fuel_to_add(896, 20500) should return 4520.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fuel_to_add(896, 20500), 4520)`)
}})

fuel_to_add(1000, 50000) should return 12209.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(fuel_to_add(1000, 50000), 12209)`)
}})

--seed--

--seed-contents--

def fuel_to_add(current_gallons, required_liters):

    return current_gallons

--solutions--

import math
def fuel_to_add(current_gallons, required_liters):
    liters_per_gallon = 3.78541
    current_liters = current_gallons * liters_per_gallon
    if current_liters >= required_liters:
        return 0
    liters_needed = required_liters - current_liters
    return math.ceil(liters_needed / liters_per_gallon)