take 5 employee name inputs and store in a list, take corresponding age in second list. display minimum age and corresponding name in python

main.py
#empty lists to store employee names and ages
names = []
ages = []

#take input of employee names and corresponding ages
for i in range(5):
    name = input("Enter name of employee {}: ".format(i+1))
    age = int(input("Enter age of employee {}: ".format(i+1)))
    
    #add names and ages to respective lists
    names.append(name)
    ages.append(age)

#calculate minimum age
min_age = min(ages)

#print name(s) of employee with minimum age
print("The youngest employee(s) is/are:")

for i in range(5):
    if ages[i] == min_age:
        print(names[i])
558 chars
23 lines

In this code, we first create two empty lists, one to store employee names and another to store their corresponding ages. We then use a for loop to take input of employee names and ages one by one and append them to their respective lists.

Next, we use the built-in min() function to calculate the minimum age from the ages list. We then use another for loop to iterate over the ages list and print the name(s) of employee(s) with the minimum age using conditional statements.

gistlibby LogSnag