2

I'm trying to get make a program that will print all the prime numbers within the argument I pass to it, so far I've made python respond with a True or False if it is prime or not.

prime = []
prime_list = []
def check_prime(user_input):
    for x in range(2, user_input):
        if float(user_input) % x > 0:
            prime = True
        else:
            prime = False
            break
    print prime
check_prime(int(raw_input("get prime numbers up to: ")))

Here is the program where it successfully returns if the number is prime or not(I think)

What I am trying to do is get all the prime numbers and store them into a list, then print them all out when it's finished. I've been picking away at this program for at least a week and I just can't figure it out.

Please pointers only, no finished version.

CrackSmoker9000
  • 197
  • 2
  • 12

1 Answers1

1

You have made a function which prints out True or False depending on whether a number is prime.

The next step is to make it return True or false.

Here is an example of a different test which you can adapt for your own needs.

def is_even(number):
    if number % 2 == 0:
       return True
    else:
        return False

$ is_even(6)
True
$ answer = is_even(6)
$ print(answer)
True

The next step is to loop through all the numbers that you want to consider, and only store them if they are prime. (You could also just print them if that's all you need.)

avoid3d
  • 610
  • 5
  • 12