A positive integer n is said to be perfect if the sum of the factors of n, other than n itself, add up to n. For instance 6 is perfect since the factors of 6 are {1,2,3,6} and 1+2+3=6. Likewise, 28 is perfect because the factors of 28 are {1,2,4,7,14,28} and 1+2+4+7+14=28.

Write a Python function perfect(n) that takes a positive integer argument and returns True if the integer is perfect, and False otherwise.

3 Days
Discussion Span
Last Post by rubberman

A few problems with your new post. The title doesn't work as you already tagged the post as being about python. Next there is no question here. It looks like a copy and paste of your homework or assignment without showing what you wrote so far.

Before you reply read this -> https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

Share your code so far and ask about where it fails. Members usually answer questions but here, no question.

Edited by rproffitt: Spelling


What have you tried? This is what everybody wants to know when you ask a homework question. We don't know what you know about programming in python. Obviously you must have learned how to define a function, that's a starting point.

Let's take it the other way around. If I ask: is 30 a perfect number? is 120 a perfect number? is 2448 a perfect number? How will you find the answer? Once you know that, you can start teaching the computer how to find the answer.


Your first problem here is the factorization of any random number. The second is to see if the factors sum up to the number itself. The function is the simple part. It should take a single argument (the number) which is factored and summed in the function. From there the answer is either true or false.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.