Python - Getting prime numbers -
this question has answer here:
- fastest way list primes below n 29 answers
i'm trying make program print prime numbers within argument pass it, far i've made python respond true or false if prime or not.
prime = [] prime_list = [] def check_prime(user_input): 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 to: ")))
here program returns if number prime or not(i think)
what trying prime numbers , store them list, print them out when it's finished. i've been picking away @ program @ least week , can't figure out.
please pointers only, no finished version.
you have made function prints out true or false depending on whether number prime.
the next step make return true or false.
here example of different test can adapt 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 loop through numbers want consider, , store them if prime. (you print them if that's need.)
Comments
Post a Comment