Input a number and check if the number is a prime or composite number.
- Details
- Category: 11th Class computer practicals
- Published: Friday, 11 June 2021 05:51
- Written by Super User
- Hits: 453
number=int(input('enter the number'))
upto=int(number/2)
prime=True
for i in range(2,upto+1):
if(number%i==0):
prime=False
break
else:
prime=True
if(prime==True):
print('prime number')
else:
print('composite number')
Explanation: Prime number is a number which is divisible by 1 or the number itself only. we are running the loop from 2 till half of the number and checking each number if it can divide the given number or not. if yes then loop will break and prime flag is set to false otherwise loop will complete and prime flag is set to true. if flag is true program will print prime number, other wise composite number.