I am playing with python3.5 right now. I was working on a simple code, to find the prime numbers less than a given integer. I solved the code more by mistake and I don't know why. This is the code:
n=int(input('Enter a numeric value: '))
for num in range(2, n+1):
if num>1:
for i in range(2, num):
if (num%i)==0:
break
else:
print(num)
What I don't seem to understand is why if i write the code like above it gives a correct answer, and if i write the else statement with one more indentation, the output is different. Ex:
Enter a numeric value: 10
3
5
5
5
7
7
7
7
7
9
for:
...if num>1:
for i in range(2, num):
if (num%i)==0:
break
else:
print(num)
I feel the need to mention that I just started to learn python so please take me slow:D