Logic Building
# Take number
num = int(input("Enter a number: "))
# Calculate product of digits
product = 1
temp = abs(num)
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
Extract digits and multiply them.
Key Concepts:
- Extract last digit using modulo
- Multiply with product
- Remove last digit using integer division
- Handle negative numbers with abs()