In this example, You can findĀ the sum of digits of a number that given by user using while loop statement
Python Code:
1 2 3 4 5 6 7 8 9 10 11 12 |
num=input("Enter a number:") import array sumDigits=0 i=0 while i < len(num): sumDigits=sumDigits + int(num[i]) i=i+1 print("The total sum of digits is %s" % int(sumDigits)) |
Output: