Python Practice › Loop Programs › Program 23
Product of digits
Write a Python program to calculate the product of the digits of a number.
Input
4352
Output
Product of digits: 120
Approach
- Same as the sum, but start at 1 and multiply.
Solution
n = 4352product = 1while n > 0: product *= n % 10 n //= 10print("Product of digits:", product)Output
Product of digits: 120
Line by line
Line 2
The product starts at 1, because starting at 0 would make everything 0.
Learn the concept
New to this topic? Read the lesson, then come back.