Thursday, August 29, 2024

Sum and Product of digits in a number

 # Take input from user

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

temp = num

product = 1

sum=0

while(temp != 0):

    product = product * (temp % 10)

    sum = sum +  (temp % 10);

    temp = int(temp / 10)


print("\nProduct of all digits in", num, ":", product)

No comments:

Post a Comment