I had a similar solution, but decided on creating a dictionary for the result. This works as well:
name_list = {}
input_str = input().strip().split()
name = input_str[0]
while name != '-1':
try:
age = int(input_str[1]) + 1
name_list[name] = age
except ValueError:
age = 0
name_list[name] = age
finally:
input_str = input().strip().split()
name = input_str[0]
for k, v in name_list.items():
print(f'{k} {v}')
This is the result: