29115/check-a-number-is-prime-or-not-in-python

def main():

n = input("Please enter a number:") is_prime(n) def is_prime(a): x = True for i in (2, a): while x: if a%i == 0: x = False else: x = True if x: print "prime" else: print "not prime" main()

If the entered number is not a prime number, it displays "not prime", as it is supposed to, but if the number is a prime number, it doesn't display anything. Could you please help me with it?

There is an efficient way to write the same program.

The loop you wrote can be concisely rewritten in Python:

def is_prime(a): return all(a % i for i in xrange(2, a))

That is, a is prime if all numbers between 2 and a (not inclusive) give non-zero remainder when divided into a.

number = int(input("Enter the Number")) if(number==1): print(number,"is not prime Number") elif(number==0): print("Oh! Enter the natural number to check the prime or not") else: check =number//2 for i in range(2 ,check+1): if check%i==0: print("oh! sorry",number,"is not prime Number") break else: print("congratulation!",number,"is the Prime Number")

n = int (input ('ENTER NUMBER TO ...READ MORE

Hi. Good question! Well, just like what ...READ MORE

a = int (input('enter number')) num = a sum ...READ MORE

By using isAlpha () to check whether ...READ MORE

You can also use the random library's ...READ MORE

Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE

Enumerate() method adds a counter to an ...READ MORE

You can simply the built-in function in ...READ MORE

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

No, Python does not support labels and ...READ MORE

OR

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

Already have an account? Sign in.