While writing a program to find the prime numbers in a certain range, the code prints every prime number multiple times instead of just listing it once.
This is the code:
first_interval = int(input('enter the beginning of the interval'))
second_interval=int(input('enter the end of the interval'))
for digit in range((first_interval),(second_interval+1)):
if digit>1:
for i in range(2,digit):
if (digit %i)==0:
break
else: print(digit)
I was expecting every prime number in the interval (4,21) to be listed just once. What I was expecting:
7
11
13
17
19
What I got:
5
5
5
7
7
7
7
7
9
11
11
11
11
11
11
11
11
11
13
13
13
13
13
13
13
13
13
13
13
15
17
17
17
17
17
17
17
17
17
17
17
17
17
17
17
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
19
21