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

FOR PYTHON: Write a function findDigits () that takes a string as a parameter an

ID: 640939 • Letter: F

Question

FOR PYTHON: Write a function findDigits() that takes a string as a parameter and returns a list containing all of the digits that appear in the string. The digits in the list that is accumulated should be in numeric form rather than strings. If the string does not contain any digits or an empty string is provided as a parameter, the empty list should be returned. If a digit appears in the string multiple times, it will appear in the list the same number of times. The following shows several sample executions of the function:

Python 3.4.1 Shell File Edit Shell Debug Options indows Help > findDigitsi'1 2 3 .. we have begun counting! >>> findDigitsi' Testing 1. Testing 12. Testing again!') >>> findDigitsi"1 2 3 o'clock, 5 6 7 o'clock, 8 9 10 o'clock") [1, 2, 3, 5, 6, 7, 8, 9, 1, 01 >>> findDigitsi' This is a test without digits. Ho sad. ') >>> findDigits Ln: 73 Col: 4

Explanation / Answer

def findDigits(str1):
   lst = []
   for i in str1:
       if i >= '0' and i <= '9':
           lst.append(i)
   return lst