people = {
"Tanay": 16,
"Noah Simon": 18,
"Arnav Nadar": 15,
"Tarun": 14,
"Maria Branyas": 116
}
negative = {
"Bobby": -232,
"Tristan": -1,
"Mark": -12
}
def oldest_person(people):
# Setting up the variables
oldest = 0
oldest_ppl = ""
for person, age in people.items():
## IF the person's age is greater than all of the previous ages, then replace oldest with their age
if age > oldest:
oldest = age
oldest_ppl = person
## if the person's age is less than 0, then tell the person negative ages don't exist. I needed to use an elif statement because an else statement would run between toby and ian and count them as negative because toby > ian
elif age < 0:
return "You can't have negative ages..."
return str(oldest_ppl) + " is the oldest person at " + str(oldest) + " years old"
# Code so that I can print both at the same time
result1 = oldest_person(people)
result2 = oldest_person(negative)
print(result1)
print(result2)
Maria Branyas is the oldest person at 116 years old
You can't have negative ages...