Simple python program to check prime number using if else. In this program we can check the number is prime or not using if else condition in python programming language for beginners.
If Else Condition in Python
An if else clause The true or false value of an expression is determined by a Python statement. The “if” statement is executed if a condition is true. If not, the “else” statement is executed.
If else statements in Python help programmers control the flow of their code. An if statement and an else statement can be combined. If the conditional expression in the if statement resolves to 0 or a FALSE value, the else statement executes a block of code. Using this if else condition to execute python program to check prime number using if else.
Prime Number Definition
A prime number is a number greater than one that is not the product of two smaller natural numbers. A composite number is a natural number greater than 1 that is not prime.
Python Program to Check Prime Number Using If Else
num = 50
flag = False
if num > 1:
for i in range(2, num):
if (num % i) == 0:
flag = True
break
if flag:
print(num, "Its Not a Prime Number")
else:
print(num, "Is Not a Prime Number")
Output:
50
Its Not a Prime Number
C++ Program for Fibonacci Series Using Recursion
C Program for Sum and Average of n Numbers
Merge Sort in C Program With Output
C Program to Concatenate String Without Using Strcat
C Program to Check Armstrong Number Using For Loop
Swapping of Two Numbers in Java Using XOR
Sum of Two Numbers Using Recursion Java
Java Program to Reverse a Given Number Using Recursive Function