Question: please use python Question 4: Define a function named q40 that accepts a string as a parameter. After verifying that the string includes only includes
please use python
Question 4: Define a function named q40 that accepts a string as a parameter. After verifying that the string includes only includes numeric digits, count the number of even (E) and odd (O) digits. Finally, create a new string made up of these values and their sum. Repeat this process until your end result is a string containing 123 For example, '15327' contains 1 even digit (E-1), 4 odd digits(O-4) and the sum of these is 5 (E+O). The new string would be' 145. Repeating the process (E-1, -2, E+0-3) gives me .123. The function q40 should return the number of repetitions it takes to create the string .123 Example output of function q4(0 at the interactive Python prompt: >4(123') Already '123' so takes zero repetitions q4(5' 2 4'471' 1 >>>q4 ('1234567890) 2 NOTE: Your q40 function should return only the number of repetitions, it should not print anything
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
