124k views
5 votes
Write a Python code to take input of age of three people by user and determine youngest people among them

2 Answers

3 votes

Final answer:

The question requires writing a Python program to determine the youngest person based on the age input provided by the user. The code takes three ages as input, uses the min() function to find the youngest, and prints out the result.

Step-by-step explanation:

To determine the youngest among three people using Python, you can write a simple program that takes the age of three people as input, compares these ages, and then prints out the age of the youngest person. Below is the Python code that achieves this:

# Get ages of three people
age1 = int(input("Enter the age of the first person: "))
age2 = int(input("Enter the age of the second person: "))
age3 = int(input("Enter the age of the third person: "))

# Determine the youngest person
youngest = min(age1, age2, age3)

# Print the youngest age
print("The youngest person is ", youngest)

This program uses the min function to find the youngest person's age. It is a straightforward way to compare multiple numbers and find the minimum among them.

User Abdalrahman
by
4.4k points
2 votes

Answer:

# Take Ages

person1 = eval(input("Enter age of person 1 : "))

person2 = eval(input("Enter age of person 2 : "))

person3 = eval(input("Enter age of person 3 : "))

# check youngest

if person1 < person2 and person1 < person3:

print("Person 1 is youngest")

elif person2 < person1 and person2 < person3:

print("Person 2 is youngest")

elif person3 < person1 and person3 < person2:

print("Person 3 is youngest")

User Roshaw
by
4.9k points