Python Program To Demonstrate Ternary Operator

Write Python code to demonstrate ternary operator

# WAP to demonstrate the use of ternary operator.

# (on_true) if (cond) else (on_false)
age = int(input("Enter your age :--> "))
print("You are eligible to vote") if (age >+ 18) else print("You are not eligible to vote")

Output:

Enter your age :--> 54
You are eligible to vote

Enter your age :--> 14
You are not eligible to vote

<< Previous | Next >>


Leave a Reply

Your email address will not be published.