Write a recursive Python function, given a non-negative integer N, to count and return the number of occurrences of the digit 7 in N.
For example:
count7(717) -> 2
count7(1237123) -> 1
count7(8989) -> 0
--------
def count7(N):
Holder = N
LastDigit = Holder % 10 #get the last digit using mod
#if the last digit is 7 then add a tally and use the function again
if LastDigit == 7:
return (1 + count7(int(Holder/10))
else:
return (0 + count7(int(Holder/10))
count7(717)
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.