Add Up a Line

Python for AIMedium+10 XP+10

Add Up a Line

A fitness app saves each workout as one line of numbers: the minutes spent on each exercise, separated by commas.

Task: write line_total(line). It returns the total of all the numbers on the line, as a float.

  • The line may end with "\n".
  • Numbers can be whole or have a decimal point, and can be negative.
  • A number may have spaces around it, like " 4 ".
  • A blank line has a total of 0.0.

Examples

line = '10,4.5,2\n'
returns 16.5
line = '7\n'
returns 7.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