# Split input into 2 parts: name and age parts = input().split() name = parts[0] while name != '-1': # FIXME: The following line will throw ValueError exception. # Insert try/except blocks to catch the exception. age = int(parts[1]) + 1 print('{} {}'.format(name, age)) # Get next line parts = input().split() name = parts[0]

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

# Split input into 2 parts: name and age
parts = input().split()
name = parts[0]

while name != '-1':
# FIXME: The following line will throw ValueError exception.
# Insert try/except blocks to catch the exception.
age = int(parts[1]) + 1
print('{} {}'.format(name, age))

# Get next line
parts = input().split()
name = parts[0]

 

How to fix this code with try except block

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning