🐍Python Program #24: Check If a Number is Perfect | Python Programming

Published: 18 September 2025
on channel: All In Graphics
36
4

🐍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


On this page of the site you can watch the video online 🐍Python Program #24: Check If a Number is Perfect | Python Programming with a duration of hours minute second in good quality, which was uploaded by the user All In Graphics 18 September 2025, share the link with friends and acquaintances, this video has already been watched 36 times on youtube and it was liked by 4 viewers. Enjoy your viewing!