Thread: Need some help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2017
    Posts
    2
    Rep Power
    0

    Need some help


    Code:
    def problem3():
        count = 0
        for i in range(2, 10000):
            for n in range(2, i):
                if (i % n == 0):
                    break
            else:
                    count += 1
        return count
    I need some help figuring out why this is not returning a number, pretty sure it has to do with range(2, i).

    Anything anyone knows would be great
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,967
    Rep Power
    509
    all python functions return a value. Since you do not have a return statement the function returns None . None, as you know, is not a number.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2017
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    all python functions return a value. Since you do not have a return statement the function returns None . None, as you know, is not a number.
    There's a return statement at the bottom, not sure what else is wrong though
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    170
    Rep Power
    22
    If you call the function, it returns 1229. Sounds silly to ask, but are you calling the function? :-P
  8. #5
  9. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,967
    Rep Power
    509
    oh, so there is.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo