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

Write Python program with the following functions: A recursive function called s

ID: 3679702 • Letter: W

Question

Write Python program with the following functions:

A recursive function called stutter that returns a string with each character in its argument repeated. For example, if the string passed to stutter is "abc", stutter will return the string "aabbcc".

A recursive function called toNumber that returns the integer sum of all digit characters in a string. For example, the result of toNumber("ab3c7d1") would be 11. Assume that the length of any empty string is 0. (Hint: you may use the method isdigit() to check whether or not a character is a digit.)

Add a main function to test your code.

Explanation / Answer

def sutter(x):
   y=[i*2 for i in x]
   return ''.join(y)
def toNumber(digit):
return sum(int(x) for x in digit if x.isdigit())
print sutter("abc")
print toNumber("ab3c7d1")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote