I wrote this to sort the prime numbers below 30.
p=[2]
i=2
while i<30:
for x in p:
if i%x==0:
break
else:
p.append(i)
i=i+1
print p
It gives me a long and duplicated result:
I noticed if I delete a tab in front of the 7th and 8th line then the code works fine. Why is that? Shouldn't 'if' and 'else' be in the same level?