Program to find the sum of digits of a given number using a while loop in Python:

 # While loop in Python - Sum of digits of a number

num = int(input("Enter a number: "))

sum = 0

while num > 0:

    digit = num % 10

    sum += digit

    num //= 10

print("The sum of digits of the given number is:", sum)


Comments

Popular posts from this blog

Simple Python Program Code for Snake Game

Iris Flowers Classification ML Project with Code

Data exploration and scatter plot visualization in Python using Pandas and Matplotlib