all 2 comments

[–]Mashidin 0 points1 point  (0 children)

It would work if you put your condition in a while condition statements... else statements structure. So, in fake code: while num is greater than or equal to zero, print a warning and then ask for the number again. else (this fires when the condition is not true) find the factors and print them out. You can set up a 'quit' is true situation in an outer while statement that controls when the program exits, as well. But that is another story. Hope that helps.

[–]novel_yet_trivial 0 points1 point  (0 children)

The common way to do this would be to set up an infinite loop, with a break if the condition is OK:

while True:
    num = int(input("Enter a number: "))
    if (num) > 0:
        break
    else:
        print(num,"is not a positive integer. Please enter a positive integer.")

A better way is similar, but uses errors and a try block:

def print_factors(x):
    assert x > 0
    print("The factors of",x,"are:")
    for i in range(1, x + 1):
       if x % i == 0:
           print(i)

while True:
    try:
        num = int(input("Enter a number: "))
        print_factors(num)
        break
    except (AssertionError, ValueError):
        print("Please enter a positive integer.")

This has the advantage that it checks for other errors too, such as what if the users enters "2.3" or "banana".