Perfect numbers program python
<p>I'm taking an intro course for python, and in one excercise we are to write a function where we type in a number and return bool True or False, if the number is a perfect number. Then we are to create another function that takes an upperlimit and will check every number up until that limit and if it is a perfect number, to print the perfect number. As of now my problem is with the 2nd half of this excersie, and instead of printing out the perfect number, it will print out how many there are with "True". Again the first function IS suppouse to return True or False, so I'm not sure how we can get the 2nd function to print out the actual number!</p>

<pre><code>def perfect(num):
    x=1
    adding=0
    while x&lt;num:
        if num % x == 0:
            adding=adding+x
        x=x+1

    if adding==num:
        #print(num)
        return (adding==num)
    else:
        return False

def perfectList(upperlimit):
    x=1
    while x&lt;upperlimit:
        if perfect(x)==True:
            print(perfect(x))
        x=x+1
</code></pre>

<p>Your second function is very close.</p>

<pre><code>def perfectList(upperlimit):
    x=1
    while x &lt; upperlimit:
        if perfect(x)==True:
            print(x) # changed from print(perfect(x))
        x=x+1
</code></pre>

<p>you just needed to change to <code>print(x)</code> (the number) not <code>print(perfect(x))</code> , which returns whether the number is a perfect number.</p>

python function perfect-numbers