Python help with debugging

Discussion in 'Programming General' started by Anavar, Aug 5, 2014.

Thread Status:
Not open for further replies.
Python help with debugging
  1. Unread #1 - Aug 5, 2014 at 9:15 AM
  2. Anavar
    Joined:
    May 8, 2014
    Posts:
    356
    Referrals:
    0
    Sythe Gold:
    0

    Anavar Forum Addict
    Banned

    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)
     
  3. Unread #2 - Aug 5, 2014 at 11:19 AM
  4. -Ryan
    Joined:
    Aug 15, 2010
    Posts:
    6,182
    Referrals:
    3
    Sythe Gold:
    996
    Discord Unique ID:
    470294579980140545
    Discord Username:
    -Ryan#2126
    Two Factor Authentication User In Memory of Jon Heidy Summer 2016 STEVE (3)

    -Ryan Make Sythe Great Again!
    Retired Global Moderator $100 USD Donor New

    Python help with debugging

    Helped him fix the problem over Skype, going to close this now.
     
< Paying somone [07/EOC] to write me a IRC script [Trusted ONLY] | I need help for a HTML JAVA Project >

Users viewing this thread
1 guest
Thread Status:
Not open for further replies.


 
 
Adblock breaks this site