0
Can anyone teach me or give me some hints,please?
Python3: 1.write a recursive function named mean(n,d)which takes as input a positive integer and its digit count and returns an average of the digits. 2.write a recursive function named countEqSubstr(str)that counts the number of substring that begin and end with same letter. I am confused.
1 Answer
0
1. No need for the first one to be recursive. Its possible to even do it in one line though for the sake of clarity, I wont. You also dont need the digit count
In Python, integers are easily transformed to strings using the str() function. len() can be used to get the length of the string then
You can also loop through the string, adding the integer representations of the digits to each other, something like this
result = 0
for digit in digit_string:
result += int(digit)
DM me for further questions