To check that a person is eligible for voting or not, we need to check whether person’s age is greater than or equal to 18. For this we are reading age in a variable a and checking the condition a>=18, if the condition is true, “person will be eligible for voting” else not.
Ternary operator:
1 2 3 | [on_true] if [expression] else [on_false] |
Program Source Code : Python program to check eligibility for voting
1 2 3 4 5 6 7 8 9 10 | # input age age = int(input("Enter Age :")) # condition status = "Eligible" if age>=18 else "Not Eligible" # print message print("You are",status,"for Vote.") |