Python if else statement

Take input of age of 3 people by the user and determine oldest and youngest among them.

a1=int(input("Enter age1: "))

a2=int(input("Enter age2: "))

a3=int(input("Enter age3: "))

if (a1<a2<a3):

print("Oldest is a3")

elif (a1a3):

print("Oldest is a2")

elif (a1>a2>a3):

print("Oldest is a1")

else:

print("All are equal")

This is the code for getting output for the oldest among them, i don’t know what and how to add the code for getting output for the youngest among them. whats will be the code for the youngest?

What’s your actual question about this?

Python uses indentation to determine which statements are dependent on other conditions (determined for instance by the if statement).

if age1 < age2:
    # indented statements executed when the test is true
else:
    # indented statements executed when the if test is false

(The # sign marks the rest of the line as commentary)

There are also min and max built-in functions available.

1 Like