I am relatively new to python, and have been working on a problem to find the prime numbers between two inputs. I have a solution that works (helped somewhat by online searching too), but am unsure on why the else
statement shown below should not be at the same tab setting as the if
statement. If it is, though, it doesn't work correctly. Can anyone clarify this for me?
My code is here:
n1 = int(input("Enter the lower number: "))
n2 = int(input("Enter the higher number: "))
for num in range(n1, n2 + 1):
if num > 1:
for i in range(2, num):
if num % i == 0:
break
else:
print(num)