top of page
Click here to go to the home page of AskTheCode.

Finding sum of digits of a number until sum becomes single digit

Asked: Pushkar Tiwari |Category: Python

n=eval(input("Enter the value of n : ")) import math def digSum( n): sum = 0 while(n > 0 or sum > 9): if(n == 0): n = sum sum = 0 sum += n % 10 n //= 10 return sum print (digSum(n))

Recent Posts

See All

Comments


bottom of page