Check out example codes for "Determine the sum of al digits of n". It will help you in understanding the concepts better.

Code Example 1

def sum_of_digits(n): 
	sum = 0
	while (n != 0): 
		sum = sum + int(n % 10) 
		n = int(n/10) 
	return sum

Learn ReactJs, React Native from akashmittal.com