What I learned

HW

# Homework

#Create class called person
class person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

#Get a list of people and print the info of each person
def print_people(list_of_people):
    for person in list_of_people:
        print(f"Name: {person}\nAge: {list_of_people[person]}")

#Get the oldest person
def print_oldest(list_of_people):
    x = list(list_of_people.values())
    x = x.index(max(x))
    print(f"The oldest person is {list(list_of_people.keys())[x]}.")

#Create a dictionary of people
people = {}

#Add as many ppl as you want
keep_going = 'Y'
while keep_going == 'Y':
    person = input('Enter person name: ')
    people[person] = int(input('Input person age: '))
    keep_going = input('Add another person [Y/N]? ').upper()

#print the order of dictionary based on both age and alphabetical order
def print_ordered(people):
    names = list(people.keys())
    ages = list(people.values())
    names.sort()
    ages.sort()

    print(f'Ordered names list: {names}')
    print(f'Ordered ages list: {ages}')


#Menu to choose what output you want
while True:
    choice = input("Choose an option:\n1. Print info on everyone\n2. Find oldest person\n3. Order info on everyone into names and ages\n4. Exit\n")
    
    if choice == '1':
        print_people(people)
    elif choice == '2':
        print_oldest(people)
    elif choice == '3':
        print_ordered(people)
    else:
        break