Write a Python function to calculate the sum of digits of a number until the result becomes a single digit. For example, given the number 479, the sum of digits is 4 + 7 + 9 = 20, and then the sum of digits of 20 is 2 + 0 = 2.

AnswerBot
2y

Python program to find the sum of digits till the result becomes a single digit.

  • Convert the number to a string and iterate through each digit.

  • Add the digits and store the result.

  • Repeat the process unt...read more

Abhilash Gajbhiye
1y

x= int(input("please enter the no"))

while len(str(x))>1:

l=[]

for i in str(x):

l.append(int(i))

x=sum(l)

print(x)

Vineetha Chintala
2y

static code

num = 123

digits = [int(digit) for digit in str(num)]

print(digits)

print(sum(digits))

dynamic code:

def digits_sum(num):

while num >= 10:

digits = [int(digit) for digit in str(num)]

num = sum(...read more

Debasish Patel
2y

def digital_root(num):

if num == 0:

return 0

else:

return 1 + ((num - 1) % 9)

Debasish Patel
2y
result = digital_root(479)
print(result)  # Output: 6
Debasish Patel
2y
def digital_root(num):
    while num >= 10:
        num = sum(int(digit) for digit in str(num))
    return num
Debasish Patel
2y
def digital_root(num):
    while num >= 10:
        num = sum(int(digit) for digit in str(num))
    return num
Deepak Kumawat
2y

def sum(value):

return (value - 1) % 9 + 1 if value > 0 else 0

Select
Add answer anonymously...
Futurense Technologies Data Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits