Practice · Python

Practice Functions: Define & Return

Define functions with parameters, return values, and call them to reuse logic.

Functions: Define & Returnwarming python…

Rocket Stage Fuel Calculator

Write a function compute_fuel that receives a list of integers representing the masses of rocket stages (in kilograms). Each stage requires floor(mass / 10) units of fuel. The function should return the total fuel needed for all stages. If the list is empty, return 0.

Examples

compute_fuel([100])        # returns 10
compute_fuel([50,150,20])  # returns 22
Press Run to see output, or Check to grade against the tests.

Want a whole course built around functions: define & return?

Start my path — free

Adaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.