- Joined
- May 8, 2014
- Sythe Gold
- 0
- Messages
- 356
So this is what I have at the moment. This program should read in a positive integer, and print out all
the positive primes less than this integer. However, it doesn't print the prime numbers. I think there's an issue in the maths of the code, but again I'm new to python and got thrown this code to debug and am absolutely stuck. Any help would be appreciated.
the positive primes less than this integer. However, it doesn't print the prime numbers. I think there's an issue in the maths of the code, but again I'm new to python and got thrown this code to debug and am absolutely stuck. Any help would be appreciated.
Code:
def is_prime(n):
k = 3
if (n == 2):
flag = True
return flag
elif (n % 2 == 1):
flag = False
return flag
else:
while (k*k < n):
if (n % k == 0):
flag = False
return flag
break
n = int(input('Please enter positive integer: '))
for i in range(n):
if (is_prime(i)):
print(i)










