Results for “replace”

Showing 1–10 of 28

  1. Challenge

    Decimal comma

    …Predict it, find out why, accept both commas and dots with replace(), then read pressures written like 1 013,25.

    Fix the code Easy 3 stages strings replace float ValueError
  2. Challenge

    Redact the access code

    Replace all but 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
  3. Challenge

    Normalise a command

    …it prints: Command: [abort burn] Matches abort burn: True replace("_", " ") swaps every underscore for a space. Add it, and one for dashes, to the end of the chain.

    Write the code Easy 3 stages strings strip lower replace
  4. Challenge

    File name from data

    Build eng-2_2026-03-14.csv from a sensor ID and a date, then turn a name like Star Tracker A into a safe file name, and put the file in a folder of its own.

    Write the code Easy 3 stages strings f-strings lower replace
  5. Challenge

    Counter

    Refactor the level counter from "Entries per level": replace the dict and counts.get() with collections.Counter, which starts every key at 0, then list the levels from most to least common with…

    Fix the code Easy 2 stages collections Counter most_common dictionaries
  6. Challenge

    Logging instead of print

    The tank check is full of prints left over from debugging. Replace them with logging calls at the right levels, so debug records stay hidden until switched on, then give the fuel code its own named…

    Fix the code Medium 2 stages logging debug info warning
  7. Challenge

    Lookup table

    Replace a nine-branch elif that maps planets and the Moon to surface gravity with a dict and one get() lookup, keeping the output exactly the same, then loop over the dict for a weight table.

    Fix the code Medium 2 stages dictionaries refactoring lookup tables get
  8. Challenge

    Copy-pasted blocks

    Replace three copy-pasted tank-status blocks with a list of (name, level) pairs and one loop, keeping the output exactly the same, then add a fourth tank with a single list item and list the low…

    Fix the code Medium 2 stages refactoring for loop tuples lists