Regular expressions · 7 / 15 Exercise Easy

All the numbers

Objective

Create a Python program that extracts all the numbers from a text and adds them up, using re.findall.

Instructions

  • Read a line of text.
  • Get the list of all the groups of digits with re.findall(r"\d+", text).
  • If there are none, show only None.
  • If there are some, show Numbers: n1 n2 ... on the first line, in the order in which they appear, and Sum: S on the second.
Input
Compré 3 manzanas y 12 peras por 7 euros
Output
Numbers: 3 12 7
Sum: 22

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise