Hello, I made a function to define whether a number n is prime or not. But I have two problems that will be described, but first let's go to the function:
However, it has two problems:
1. When the input is 8 the output is True. That's the only error, but I don't know why.
2. It's bad optimized, I want to know if there are things that I can omit, or a better way to define if a number is prime or not
Thank you
Code:
def esprimo(n): m=str(n) if n<=1: a=False elif n==2: a=True elif int(m[-1])==(2 or 4 or 6 or 8 or 0 or 5): a=False elif n%3==0: if n!=3: a=False else: a=True elif n%7==0: if n!=7: a=False else: a=True else: a=True check=11 while check<n+1: if n%check==0: if n/check==1: pass else: a=False check+=2
1. When the input is 8 the output is True. That's the only error, but I don't know why.
2. It's bad optimized, I want to know if there are things that I can omit, or a better way to define if a number is prime or not
Thank you
Comment