[Python] Find Perfect Number using While loop in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    There is no error in this code but its not printing the result. Here, what could be the problem.

    # Using WHILE LOOP
    num = int(input('Enter any positive integer: '))
    sum1 = 0
    i = 1

    if num <= 0:
    print('Invalid Number.')
    else:
    while(i < num):
    if num % i == 0:
    sum1 = sum1 + i
    i = i + 1

    if sum1 == num:
    print(num, "is a perfect number")
    else:
    print(num, "is not a perfect number")

    Continue reading...

Compartilhe esta Página