on-internet
← Community

how to find a prime number function in python

Stack Overflow ·

I started getting back to python coding and realized I couldn't quite figure this out. I'm trying to code a prime number function. Could someone help with this? Here is my code: def is_prime(x): a = True for n in range(2, x-1): while n < x: n+=1 if x % n == 0: a = False elif n < 2: a = False else: a = True break break return a If anyone has an idea on what I'm doing wrong, please let me know. A month ago I tried this and couldn't get the logic down. I think I was stumped and didn't ever ask for help... Also, how long do you think I should try to do this for before I ask for help on average?

Comments

Sign in or sign up to comment and upvote.

No comments yet.