• Log in or sign up for an account here: https://www.sythe.org/login

Python help with debugging

Status
Not open for further replies.

Anavar

Forum Addict

Banned
Joined
May 8, 2014
Sythe Gold
0
Messages
356
Python help with debugging
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.

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)
 
Two Factor Authentication User
Discord Verified
In Memory of Jon
Heidy
STEVE
Summer 2016
Python help with debugging
Helped him fix the problem over Skype, going to close this now.
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top