I'm pretty new to Python, so for fun and exercise I've been trying to write a procedure in which I input a number, and output every prime number in the interval [0:n].

I managed to do it pretty quickly by first defining a procedure that recognises and returns primes but later on I realised that I wanted two outputs so that if the input number was prime, I'd get True , n and if it wasn't I'd get False , 0.

But now, whenever I run the procedure that gives me all the primes it always ends the list with "None" and I can't figure out why!

Heres the definitions:

- Code: Select all
`def round_number(n):`

num = n + 0.5

return int(str(num)[:str(num).find('.')])

def prime(n):

i = 1

while i <= n:

i = i + 1

if n / (i * 1.0) == round_number(n / (i * 1.0)):

break

if n / i != 1:

return False , 0

else:

return n / i == 1 , n

def every_prime(n):

i = 2

while i <= n:

is_it_prime , the_prime = prime(i)

if is_it_prime == True:

print the_prime

i = i + 1

Thank you for your help