+ 1

Why is it not working

def is_prime(num): return [i for i in range(2,num) if num%i == 0] == [] def get_prime(): num = 2 while True: if is_prime(num): yield num num += 1 for i in get_prime(): print(i)

11th Jun 2020, 5:22 AM
Tanjir Ahmed
Tanjir Ahmed - avatar
7 odpowiedzi
+ 4
You should indent back the line: num += 1 so that it always gets executed, not only in case the if statement is True...
11th Jun 2020, 5:43 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
change while True to while num <10000
11th Jun 2020, 6:17 AM
Oma Falk
Oma Falk - avatar
+ 3
Valmob101 Yes.the problem is there too. It gives output sometimes and sometimes not.
11th Jun 2020, 6:18 AM
SOUMYA
SOUMYA - avatar
+ 2
11th Jun 2020, 6:10 AM
SOUMYA
SOUMYA - avatar
+ 1
dedent num+=1
11th Jun 2020, 5:42 AM
Oma Falk
Oma Falk - avatar
+ 1
Move num += 1 one indentation back. It is basically the memory issue with sololearn. Sometimes it works and sometimes not. Use for loop or while loop with condition instead to get result.
11th Jun 2020, 6:09 AM
Valmob101
Valmob101 - avatar