One Reply for Two Errors

Python for AIMedium+10 XP+10

One Reply for Two Errors

A data feed sends values that are meant to be whole numbers. Some arrive as unreadable text like "seven". Some are missing and arrive as None.

Write double_values(values) that returns a new list where each value becomes:

  • int(value) * 2, if that works
  • the text "skip", if int() raises a ValueError or a TypeError

Use one except block for both errors.

Examples

values = ["7", "seven", None]
returns [14, 'skip', 'skip']
values = []
returns []

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run