0
Can you say what is error in this program.To find prime number from 1 to 8.
for i in range(1,9): j=2 while j<i: if i%j==0: break j=j+1 print(i) Output: It's printing 3 5 5 5 7 7 7 7 7 > Expected output 1 2 3 5 7
1 Resposta
+ 3
you can use the >else< part of the while loop. put your print statement in there:
for i in range(1,9):
j=2
while j<i:
if i%j==0:
break
j=j+1
else:
print(i)