+ 2

I don't why this code output the numbers more time.If I change the code it raises the error.can anybody solve this problem.

Prime number in given intervals https://code.sololearn.com/c87FRe03Q6Lc/?ref=app

17th Jan 2022, 7:05 AM
ᎷᏒ.ፈᎧᎮᏋᏒ
ᎷᏒ.ፈᎧᎮᏋᏒ - avatar
4 RĂ©ponses
+ 4
Instead of if-else, try using a for-else clause in inner loop for: if: break else: print()
17th Jan 2022, 7:22 AM
Simba
Simba - avatar
+ 3
Thanks guys problem solved
17th Jan 2022, 7:44 AM
ᎷᏒ.ፈᎧᎮᏋᏒ
ᎷᏒ.ፈᎧᎮᏋᏒ - avatar
+ 2
Thanks for your answers
17th Jan 2022, 7:23 AM
ᎷᏒ.ፈᎧᎮᏋᏒ
ᎷᏒ.ፈᎧᎮᏋᏒ - avatar
+ 1
ᎷᏒ.ፈᎧᎮᏋᏒ in nested loop, you are printing that much times the number is not completely divisible(remainder!=0) by number less than it. So lets you have 5 Then 5%2!=0 #print 5 5%3!=0 #print 5 5%4!=0 #print 5 So now you get the issue in the code... Solution: Set a flag which will keep track if nested loop is broken or not. If it broke means no prime otherwise prime...
17th Jan 2022, 7:17 AM
saurabh
saurabh - avatar