function - python - sieve of Eratosthenes when number is prime print "1" when not print "0" -


i must create function f(n) value 1 when number prime or value 0 when isn't prime. code working prints in revers order. example: f(6)= 0 0 1 1 0 1 0

def prime(n):     if n<2: return false     in range(2,n):         if n%i == 0:             return false     return true  def f(n):     print('0', end=' ')     a=1     while a<=n:         n=n-1         print('1' if prime(n) else '0', end=' ')  f(6) 

reverse loop like:

def f(n):   print('0')   in range(1, n+1):     print('1' if prime(a) else '0') 

ps have seen examples of how actually implement sieve of eratosthenes in python on stack overflow, worth searching better solution.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -