Product of Digits
Calculate product of digits of a number.
IntermediatePhase 2 - Level 2: Number-based Looping LogicExample 11 of 14
product-of-digits.py
1# Take number2num = int(input("Enter a number: "))34# Calculate product5product = 16temp = abs(num)7if temp == 0:8 product = 09else:10 while temp > 0:11 digit = temp % 1012 product *= digit13 temp //= 101415print(f"Product of digits: {product}")
Output
Enter a number: 234 Product of digits: 24
What's going on
Multiply all digits together.
Key Concepts:
Extract digits using modulo
Multiply with product
Handle zero case
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum