Logic Building
# Take number
num = int(input("Enter a number: "))
# Calculate product
product = 1
temp = abs(num)
if temp == 0:
product = 0
else:
while temp > 0:
digit = temp % 10
product *= digit
temp //= 10
print(f"Product of digits: {product}")Output
Enter a number: 234 Product of digits: 24
Multiply all digits together.
Key Concepts:
- Extract digits using modulo
- Multiply with product
- Handle zero case