Read the Price Tag

Python for AIMedium+10 XP+10

Read the Price Tag

Prices copied from a website arrive as text with junk around them: spaces, tabs, line breaks and dollar signs, at either end, in any mix.

Task: write price_value(tag) that returns the price as a float.

  • Only the ends are messy. The number in the middle is always a normal number like 19.99 or 5.
  • There may be several $ signs, and spaces can sit between them and the number.

Examples

tag = " $$19.99 "
returns 19.99
tag = "$5"
returns 5.0

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