Python

5 Python Conditional Statement 4 – If..else..elif

If..else..elif

If..else..elif : code

if person_age < 4:
ticket_price = 0
elif person_age < 18:
ticket_price = 5
elif person_age < 65:
ticket_price = 10
else:
ticket_price = 5

Python does not require an else block at the end of an if-elif chain. Sometimes an else block is useful; sometimes you can avoid using.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s