-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfect.py
22 lines (19 loc) · 847 Bytes
/
perfect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def getInput(): #Function to take User Input
usrInput = int(input("Enter an integer to test : "))
return usrInput
def isPerfect(testcase): #Function to test if the given testCase is Perfect or NOT
sum = 1 #Sum Variable to store ongoing sum
factor = 2
while factor<=(testCase/2):
if(testCase%factor==0): #To Check if the factor divides the testCase completely
sum+=factor
factor+=1
return sum==testCase #Checking if the Ongoing Sum equals the TestCase
def displayOutput(testCase, result): #Display function to handle Outputs to the Console
if(result): #Checking result from 'isPerfect' Function
print(testCase,"is a Perfect Number")
else:
print(testCase,"is NOT a Perfect Number")
#Main Program Flow
testCase = getInput()
displayOutput(testCase,isPerfect(testCase))