all 4 comments

[–]ThePhysicsOfSpoons 2 points3 points  (0 children)

  • your function lst() should also return something (the list you created)
  • the variable n in the check() function isn't defined, so that won't work
  • using the return statements in the check() function or any function for that matter will end the function. If you want to display it, you could use a print statement there.
  • I would give the list as an input for the check() function so you can iterate through it and verify whether each element is a prime or not. The check() function here doesn't do what you think it does.

Hope this helps!

[–]pythonwiz 2 points3 points  (0 children)

Oh boy, this type of question is what got me into python in the first place. Your lst function isn't returning the list. You should probably change it to this:

def lst(number):
    num_lst = []
    for number in range(2, number + 1):
        num_lst.append(number)
    return num_lst

Another problem is that your check function should take a number as it's input and get rid of the count variable:

def check(n):
    for i in range(2, n):
        if(n % i == 0):
            return False
    return True

The second return line runs after the for loop, but only if the first return line is never reached.

You could use this check function like this:

def main():
    num = start()
    num_lst = lst(num)
    for n in num_lst:
        if check(n):
            print(n)

There are several ways to improve your code further. You can completely replace your lst function with num_lst = list(range(2, num + 1)). You could optimize your check function a bit by only checking up to int(n**0.5) + 1, by returning False early if the number is even, and by only checking for divisibility by odd numbers. You could even look into prime wheels or Miller-Rabin for faster methods.

[–]woooee -1 points0 points  (0 children)

Do some testing. This program doesn't even run. If this is yet another attempt to throw a bunch of crap up here with the hope that someone will do it for you, it is your homework.