In the previous article, we have seen how can write if, if-else, and nested if conditional statements in python. In this article let us use the conditional statements to write some Python programs.
Table of Contents
Check for Prime Number
The below Python program takes input from the user and checks if the input number is a prime number or not.
a=int(input("Enter the number")) if(a%2==0): print("number is prime") else: print("Number is not prime")
Check if a number is a positive number, negative number or zero using nested if statement
Below Python program takes input from the user and checks whether a given number is a positive number, negative number or zero. In this program, we will use the nested if the condition
a = float(input("Enter the number: ")) if a >= 0: if a == 0: print("Number is Zero") else: print("Number is Positive number") else: print("Number is Negative number")
Check if a number is a positive number, negative number or zero using elif statement
Below Python program takes input from the user and checks whether a given number is a positive number, negative number or zero. In this program, we will use the nested if the condition, like if and elif.
a = float(input("Enter the number: ")) if a > 0: print("Number is Positive number") elif a == 0: print("Number is Zero") else: print("Number is Negative number")