curriculum/challenges/english/blocks/daily-coding-challenges-python/68c497f3aaefc9fd9f1b0e25.md
For the final day of Space Week, you will be given the mass in kilograms (kg) of a payload you want to send to orbit. Determine the amount of fuel needed to send your payload to orbit using the following rules:
For example, given a payload mass of 50 kg, you would need 10 kg of fuel to lift it (payload / 5), which increases the total mass to 60 kg, which needs 12 kg to lift (2 additional kg), which increases the total mass to 62 kg, which needs 12.4 kg to lift - 0.4 additional kg - which is less 1 additional kg, so we stop here. The total mass to lift is 62.4 kg, 50 of which is the initial payload and 12.4 of fuel.
launch_fuel(50) should return 12.4.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(launch_fuel(50), 12.4)`)
}})
launch_fuel(500) should return 124.8.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(launch_fuel(500), 124.8)`)
}})
launch_fuel(243) should return 60.7.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(launch_fuel(243), 60.7)`)
}})
launch_fuel(11000) should return 2749.8.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(launch_fuel(11000), 2749.8)`)
}})
launch_fuel(6214) should return 1553.4.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(launch_fuel(6214), 1553.4)`)
}})
def launch_fuel(payload):
return payload
def launch_fuel(payload):
total_mass = payload
additional_fuel = total_mass / 5
total_fuel = additional_fuel
while additional_fuel >= 1:
total_mass += additional_fuel
additional_fuel = (total_mass / 5) - total_fuel
total_fuel += additional_fuel
return round(total_fuel, 1)