In this python basic program, we will check the whether the given number is a prime number.
Steps to solve the program
- Take a number as input through the user and create a count variable and assign its value equal to 0.
- Use for loop with the range function to check whether a number is a prime number or not.
- If a number divides the input number then add 1 to the count variable.
- If a number is divisible by 1 and by itself then it is a prime number.
- Print the output.
num = int(input("Enter a number: "))
count = 0
for i in range(1,num+1):
if num%i == 0:
count += 1
if count == 2:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")
Output :
Enter a number: 53
53 is a prime number