Final answer:
To handle an exception in the given program where the second input on a line is a string instead of an integer, we need to add try and except blocks to catch the ValueError exception and output 0 for the age.
Step-by-step explanation:
The given program reads a list of single-word first names and ages, and outputs that list with the age incremented. To handle the scenario where the second input on a line is a string instead of an integer, we need to add try and except blocks to catch the ValueError exception and output 0 for the age.
Here is an example of how to modify the code:
while True:
try:
name, age = input().split()
age = int(age) + 1
print(name, age)
except ValueError:
print(name, 0)
if age == -1:
break
This modified code will catch any ValueError exceptions and print the name with 0 age when it occurs.