I'm trying to make a program which will output all prime numbers in a random numerical segment [a,b]. However I also need this program to use the inner for
loop as well as for-else
construction. I know that there are other great solutions out there to this problem, but I try tackling the issue using ONLY above-mentioned structures. The problem is that it doesn't even output prime numbers, but all numbers in the segment.
Input: a, b (where a,b belong to the set of integers)
Output: prime numbers in the segment: x1,x2,...,xN
Here's my solution:
# prime nums
x = int(input())
y = int(input())
res = 'prime numbers: '
for i in range (x,y,1):
for j in range (i-1,0,-1):
if (i%j == 0):
pass
else:
res=res+str(i)
print(res)
Thanks in advance!