🐍Python Program #24: Check If a Number is Perfect | Python Programming
💡 What is a Perfect Number? It’s a number that equals the sum of its proper divisors.
Example: 28 → 1 + 2 + 4 + 7 + 14 = 28 ✔
In this tutorial, you’ll learn:
✅ How to find divisors of a number
✅ How to check if a number is perfect
✅ A common math-based Python program for practice
Perfect for coding practice, assignments, and interviews!
#Python #PerfectNumber #PythonForBeginners #PythonPrograms #PythonPractice #CodingBasics #LearnPython
Logic:
1. A Perfect Number is a number that is equal to the sum of its proper divisors (excluding itself).
Example: 28 → divisors = 1, 2, 4, 7, 14
Sum = 1 + 2 + 4 + 7 + 14 = 28 ✔
2. Ask the user to enter a number.
3. Find divisors:
→ Loop from 1 to num-1 (or num//2 for efficiency).
→ If num % i == 0 → add i to sum.
4. Compare the sum with the original number:
→ If equal → Perfect number.
→ Else → Not perfect.
Code:
num = 28
sum_of_divisors = 0
for i in range(1, num):
if num % i == 0:
sum_of_divisors += i
if sum_of_divisors == num:
print(f"{num} is a Perfect number")
else:
print(f"{num} is NOT a Perfect number")
👉 Perfect for Python beginners and school/college projects!
📌 More Python Tutorials (Subscribe to stay updated!):
👉 Python in 5 Minutes: Super Fast Beginner Guide
• Python in 5 Minutes: Super Fast Beginner G...
👉 Python Variables and Data Types | Explained in 3 minutes with Examples | Python for Beginners
• Python Variables and Data Types | Explaine...
👉 Master Python Loops (For loop & While loop) in Just 5 Minutes | Python For Beginners
• Master Python Loops (For loop & While loop...
💻Coding Python Calculator Program 🧮🐍
• 💻Coding Python Calculator Program 🧮🐍
👉 How to Check If List is Empty in Python 🐍💻
• How to Check If List is Empty in Python 🐍💻
👉 How to Reverse a String in Python Like a Pro!
• How to Reverse a String in Python Like a Pro!
👉 Python Lists | 5 Cool Tricks of Lists in Python - You must know!
• 5 Cool Tricks To Use Lists in Python - You...
👉3 Ways to Reverse a String in Python — No Slicing! | Python for beginners
• 3 Ways to Reverse a String in Python — No ...
👉 Python Programs | Python Programming - Playlist for logic building and practice
• Python Programs | Python Programming - Pla...
💡 If this helped you, don’t forget to Like 👍, 💬Drop a comment and
🔔Subscribe for more Python tutorials every week!
#Python #PythonForBeginners #PythonProjects #BeginnerPython #PythonLogic #computerprogramming #pythonprogramming #perfect #perfectnumber #code #loop #coding #programming #number #conditionals #ifelsestatement #pythonprograms
Auf dieser Seite können Sie das Online-Video 🐍Python Program #24: Check If a Number is Perfect | Python Programming mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer All In Graphics 18 September 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 36 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!