Question: You will write two functions in this challenge. First write a function called rec_dig_sum that takes in an integer and returns the recursive digit sum
You will write two functions in this challenge. First write a function called rec_dig_sum that takes in an integer and returns the recursive digit sum of that number. Examples of recursive digit sums: 101 => 1+0+1 = 2 191 => 1+9+1 = 11 => 1+1 = 2 5697 => 5+6+9+7 = 27 => 2+7 = 9 Then use that function within another function called distr_of_rec_digit_sums, that returns a dictionary where the keys are recursive digit sums, and the values are the counts of those digit sums occurring between a low and high (inclusive) range of input numbers. Assume low and high are positive integers where high is greater than low, and neither low nor high are negative. Your function should return a dictionary, not just print it. You can test your code as many times as you need. Your code will save if you need to come back later.
This DID NOT WORK:.
-----------------
def rec_dig_sum(value): dig_sum=0 while(value>0): dig_sum+=value%10 value=int(value/10) if(dig_sum>=10): return rec_dig_sum(dig_sum) return dig_sum
def distr_of_rec_digit_sums(low,high): dictionary={} for i in range(low,high+1,1): dig_sum=rec_dig_sum(i) if dig_sum in dictionary.keys(): dictionary[dig_sum]=1+dictionary[dig_sum] else: dictionary[dig_sum]=1 return dictionary
-------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
