Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Python » Python programs

Python | Example of Ternary Operator



Python Ternary Operator Example: 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.
Submitted by Pankaj Singh, on October 06, 2018

Given age of a person and we have to check whether person is eligible for voting or not using Ternary operator.

Syntax:

    [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.

Example:

    Input:
    Enter Age :21

    Output:
    You are Eligible for Vote.

Program:

# 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.





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.