id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav1780@gmail.com 07_recursion > single_digit_sum
prev  |  next  |  chance

Define a function that when passed an integer, returns the single-digit sum of its digits. For example, if n = 999999997, the sum of the digits is 79, but since its not a single-digit number, we compute the sum of its digits, which is 16. It's still not a single-digit number, so we repeat the process, finally yielding 7.


single_digit_sum(999999997) → 7
single_digit_sum(39) → 3
single_digit_sum(100) → 1

...Save, Compile, Run (ctrl-enter)

def single_digit_sum(n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 2 Post-solution available

Copyright Nick Parlante 2017 - privacy