Answer to Question #305975 in Python for prik

Question #305975

Take input of age of 3 people by user and determine oldest and youngest among them, using if-else statement

1
Expert's answer
2022-03-04T04:04:48-0500
age1 = int(input("Enter age Person 1: "))
age2 = int(input("Enter age Person 2: "))
age3 = int(input("Enter age Person 3: "))
print()
if (age1 > age2) & (age1 > age3):
    print('Person 1 is the oldest')
    if age2 < age3:
        print('Person 2 is the youngest')
    else:
        print('Person 3 is the youngest')
elif (age2 > age1) & (age2 > age3):
    print('Person 2 is the oldest')
    if age1 < age3:
        print('Person 1 is the youngest')
    else:
        print('Person 3 is the youngest')
else:
     print('Person 3 is the oldest')
     if age1 < age2:
         print('Person 1 is the youngest')
     else:
         print('Person 2 is the youngest')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS