Question: So I am supposed to write a Python program that will identify and print all the perfect numbers in some closed interval [ 2, n ], one per line. We only have to use nested while loops/ if-else statements. I did it somehow using a for loop, but can't figure out the same using a while loop. I'd appreciate your help if you could show me how to translate my code into a while loop. Thanks guys. Here's what I have:

```
limit = int(input("enter upper limit for perfect number search: "))

for n in range(2, limit + 1):
    sum = 0
    for divisor in range(1, n):
        if not n % divisor:
            sum += divisor
        if sum == n:
            print(n, "is a perfect number")

```

Answer: 
I leave you an alternative of the code:

```
def perfect(x:int, i:int = 2, z:int = 0) -> int or bool:
    while z != x:
        z = (2**(i-1))*((2**i)-1)
        i+=1
        if z > x:
            break
            return False
    return z

if __name__ == '__main__':

    n = int(input("Digita un número:  "))
    print('Es un numero perfecto ' if n == perfect(n) else 'No es un numero perfecto')

```
```py
T = int(input())
list1 = list()
for i in range(0,T):
    N = int(input())
    list1.append(N)
    list1 = [int(i) for i in list1]
sum = 0
for ele in list1:
    for j in range(1,ele):
        if ele % j == 0:
            sum = sum + j
    if sum==ele:
        print('True')
    else:
        print('false')

```