Chapter 22: if-elif-else statement

The elif statement is used when we need to check multiple conditions, one after another.

string = ("Ticket Price according to your age.")
print(string.center(len(string)+8,"*"))
age = int(input("Enter your age: "))
if age == 0 or age < 0:
  print("Age can't be zero or negative.")
elif 1 < age <= 3:
  print("Ticket Price: 0")
elif 4<=age<=10:
  print("Ticket Price: 100")
elif 11<=age<=60:
  print("Ticket Price: 200")
else:
  print("Ticket Price: 150")
Output 1:
****Ticket Price according to your age.****
Enter your age: 2
Ticket Price: Free
Output 2: 
****Ticket Price according to your age.****
Enter your age: 7
Ticket Price: 100
Output 3:
****Ticket Price according to your age.****
Enter your age: 15
Ticket Price: 200
Output 4:
****Ticket Price according to your age.****
Enter your age: 65
Ticket Price: 150