Results for “len”

Showing 1–10 of 68

  1. Challenge

    Crew roster

    …member and the crew size from a list with [0], [-1] and len(), then add the second in command and the whole roster joined into one line.

    Write the code Easy 2 stages lists indexing negative index len
  2. Challenge

    Missing index

    …an IndexError. Predict it, work out the valid indexes with len(), fix it with [-1], then print the first, middle and last readings for any length.

    Fix the code Easy 3 stages lists indexing IndexError len
  3. Challenge

    Readings summary

    …engine readings with min(), max() and a mean from sum() / len(), then add the spread and make the summary cope with an empty list instead of crashing.

    Write the code Easy 2 stages lists min max sum
  4. Challenge

    Redact the access code

    …the last four characters of an access code with * using len(), slicing and string repetition, then find a code inside a log line and mask it there before the line is saved.

    Write the code Medium 2 stages strings slicing len replace
  5. Challenge

    Clear error messages

    …quietly returns negative fuel for a negative burn length. Make it raise ValueError with a message that shows the bad value, then raise TypeError, checked first, when the length isn't a number at all.

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

    Safe number input

    The burn length is typed in by hand, and a typo stops the program with a ValueError. Catch it with try and except, keep asking until the input is a number, then also turn away zero and negative…

    Write the code Easy 2 stages errors try except ValueError
  7. Challenge

    Fuel for a burn

    Ask for an engine burn length with input(), turn it into a number with float() and work out the propellant it uses, then read the tank level too and show what the burn leaves.

    Write the code Easy 2 stages input float type conversion multiplication
  8. Challenge

    Test the error

    …wrong error fails it, then pin down the message and the lengths that must still work.

    Write the code Medium 2 stages testing assert try except
  9. Challenge

    Command parser

    …('burn', 0.5) REJECTED "burn": burn needs one value: the length in seconds REJECTED "burn ten": burn length must be a number: ten REJECTED "burn -4": burn length must be positive: -4 REJECTED "dance"…

    Write the code Medium 2 stages project parsing strings split