+ 1
How to print prime numbers list in python?
Here's the code I have written that I think should be giving a list of prime numbers, but it is not working. Please give me suggestions so that I can fix this code. def is_prime(): lists = [2, 3,] x = 4 for n in range(2, x-1): if x % n != 0: lists.append(x) x += 1 return lists print(is_prime())
7 Réponses
+ 2
Here's the properly indented code...
def is_prime():
lists = [2, 3,]
x = 4
for n in range(2, x-1):
if x % n != 0:
lists.append(x)
x += 1
return lists
print(is_prime())
thanks for help..
+ 1
That's great piece of code..and very efficient too👍....
but if you can tell me what 's wrong with my code that would be better.....
I am grateful for your help
+ 1
It's Ok...thanks for your help...I appreciate that☺️☺️
0
I can't run your code... It's not well indented
0
Here's mine
def is_prime:
for i in range(1,100):
if i==3 or i==5 or i%2!=0 and i%3!=0 and i%5!=0:
print(i)
is_prime()
0
Okay... I'll check it now
0
Sorry I can't figure it out.... It's not just looking correct