Hi guys, new here, and new to python. And I thought I would ask for a bit of guidance on this piece of code I'm working on.
The following block of code is supposed to output all positive factors of the entered integer. However, it does not work properly. The range of num goes from 0 to num. However, modulo by zero is impossible. I have tried limiting the range with
range(1,num)
. But it does not provide the correct outputs.
My Bugged Code:
num = int(raw_input("What number would you like to know the factors of? "))
print "The positive factors of " + num + "are: "
for test in range(num): #range goes from 0 -> num, on the first instance,test = 0
if num%test == 0: #num cannot be modulo by 0
print num
Can anyone provide some sort of guidance, and point me in the right direction?
Thanks,
ZigZag