Home »
Python »
Python Programs
Ternary Operator Program in Python
Python Ternary Operator Program: Here, we are implementing a program that will read age of a person and check whether person is eligible for voting or not using ternary operator.
By Pankaj Singh Last updated : April 10, 2023
Problem Statement
Given age of a person and we have to check whether person is eligible for voting or not using Ternary operator.
To solve this problem, we will use ternary operator, consider the below syntax of ternary operator,
[on_true] if [expression] else [on_false]
Here,
- [on_true] is the statement that will be execute if the given condition [expression] is true.
- [expression] is the conditional expression to be checked.
- [on_false] is the statement that will be executed if the given condition [expression] is false.
Sample Input/Output
Input:
Enter Age :21
Output:
You are Eligible for Vote.
Ternary Operator Program Code in Python
# input age
age = int(input("Enter Age :"))
# condition
status = "Eligible" if age>=18 else "Not Eligible"
# print message
print("You are",status,"for Vote.")
Output
Enter Age :21
You are Eligible for Vote.
Python Basic Programs »