def mod(a): return lambda x: x % a != 0 or x == a; def sieve(s, n): s = filter(mod(s[n]), s) if (s[n+1] > s[-1]**0.5): return s; else: return sieve(s, n+1) def start(x,y): s = range(x, y) print sieve(s, 0) x=int(input('Give start :')) y=int(input('Give end :')) start(x,y)