Sep-11-2018, 07:55 PM
Please try the sample code.
With 'for n in range(2,10)'
First line of output should always be: n=2, x=2 (this is never output!)
Again with 'for n in range(4,10)' (or any non-prime number as range start)
Output works as expected now! n=4, x=2
SAMPLE CODE:
With 'for n in range(2,10)'
First line of output should always be: n=2, x=2 (this is never output!)
Again with 'for n in range(4,10)' (or any non-prime number as range start)
Output works as expected now! n=4, x=2
SAMPLE CODE:
for n in range(2, 10): for x in range(2, n): # ignored 1st-time through inner loop # when n range starts on prime number print('n=' + str(n) + ', x=' + str(x)) if n % x == 0: print(n, 'equals', x, '*', n//x) break else: # loop fell through without finding a factor print(n, 'is a prime number')