Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON: QUESTION 5. Write a function extractNumber() that takes a string as a pa

ID: 3678335 • Letter: P

Question

PYTHON:

QUESTION 5. Write a function extractNumber() that takes a string as a parameter. The function accumulates all of the digits in the string into a new string and then returns the numeric value associated with that string. The digits should be accumulated in the order found in the original string, moving from front to back. You can assume that the string provided as a parameter contains at least one digit. Some sample runs of this function are provided below. 7 Python Shell File Edit Shell Debug Options Windows Help extractNumber 3 2 1 boom 321 val. extractNumber I wish I had 15 dollars for 3 sandwiches. val. 153 val 3 459

Explanation / Answer

#!/usr/bin/python
import re
# Function definition is here
def extractNumber( s ):
i=map(int, re.findall(r'd+', s))
i=map(str,i)
j= ''.join(i)
  
return int(j)

# Now you can call function
print extractNumber( s="3 2 1 boom")