Product of Digits
Print the product of digits of a given number.
BeginnerPhase 2 - Level 1: Basic LoopingExample 10 of 14
product-of-digits.py
1# Take number2num = int(input("Enter a number: "))34# Calculate product of digits5product = 16temp = abs(num)78while temp > 0:9 digit = temp % 1010 product *= digit11 temp //= 101213print(f"Product of digits: {product}")
Output
Enter a number: 234 Product of digits: 24
What's going on
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()
🔗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