Results for “functions”

Showing 21–30 of 86

  1. Challenge

    Clear error messages

    …noticed until the fuel budget came out 62.5 kg short. A function that gets a value it can't work with should say so, loudly and clearly, at the moment it happens. Raise ValueError Make fuel_needed()…

    Write the code Medium 2 stages errors raise ValueError TypeError
  2. Challenge

    Any number of values

    …pass from the database, sometimes just two numbers. A function that wants a list makes every one of those calls a little clumsier than it needs to be. Write an average that takes the values as they…

    Write the code Easy 2 stages functions *args unpacking keyword-only arguments
  3. Challenge

    Shadowed fuel

    refuel() assigns to fuel_kg inside the function, creating a local variable and leaving the global fuel unchanged. Predict the last line, compare both values, fix it by returning the total, then write…

    Fix the code Medium 3 stages functions scope local variables global variables
  4. Challenge

    Changed the caller's list

    …find out how the preview reached the stored list, fix the function, then write another one that leaves its input alone. Predict and run Don't run the code yet. Read it and decide what it will print on…

    Fix the code Medium 3 stages functions lists mutation return
  5. Challenge

    Guard clauses

    The docking computer decides whether the ship may dock. Its function has grown one condition at a time, each inside the last, and the reason for a refusal now sits four levels deep, at the far end of…

    Fix the code Medium 2 stages functions return guard clauses refactoring
  6. Challenge

    Validate a cargo record

    …with it, not just the first problem. Write the check as a function that collects the problems, then add a rule for the ID format. Missing fields and negative mass Write validate_cargo(item) , which…

    Write the code Medium 2 stages functions return lists validation