The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an integer. At FIXME in the code, add try and except blocks to catch the ValueError exception and output 0 for the age.




Ex: If the input is:


Lee 18

Lua 21

Mary Beth 19

Stu 33

-1

then the output is:


Lee 19

Lua 22

Mary 0

Stu 34



# 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.
try:
age = int (parts [ 1 ]) + 1
print('{ }{ }'.format(name, age))
# Get next line
parts = input().split()
name = parts[0]
except ValueError:
print ('Invalid value!')
# Get next line
parts = input().split()
name = parts[0]

Answers

Answer 1

Using the knowledge of computational language in python it is possible to write a code that program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented.

Writting the code:

# Split input into 2 parts: name and age

parts = input().split()

name = parts[0]

while name != '-1':

   # Insert try/except blocks to catch the exception.

   try:

       age = int(parts[1]) + 1

       

       # printing name and age

       print('{} {}'.format(name, age))

   

   except ValueError:

       # printing name and age as 0

       print('{} {}'.format(name, 0))

   

   # Get next line

   parts = input().split()

   name = parts[0]

See more about python at brainly.com/question/18502436

#SPJ1

The Given Program Reads A List Of Single-word First Names And Ages (ending With -1), And Outputs That

Related Questions

What is output if the user types in 7? Click all that apply.

Answers

Based on the code that is given below, the output if the user types in 8 is option C:  C.

What is the line of code about?

The code above is an if statement: A will not be printed since the user had specified x = 8, which does not satisfy the criterion x!= 8 (!= stands for not equal).

Since x must be greater than or equal to 10 in order to satisfy the criterion for "B" to be printed, "B" will not be printed because x does not meet the condition.

Also x is less than 10, the requirement of x10 is satisfied, and "C" will be printed as a result.

Learn more about coding from

https://brainly.com/question/20312196

#SPJ1

See correct question below

x = int (input ("Enter a number: "))

if (x != 8):

print ("A")

if (x >= 10):

print ("B")

if (x < 10):

print ("C")

if (x % 2 == 1):

print ("D")

What is output if the user types in 8? Click all that apply.

A

B

C

D

4. Some programs add extra characters,
called a(n)________, to
a file name.

Answers

Answer:

big letters

Explanation:

in order for the file to be more impacable

Other Questions
Translate the following statement into a mathematical equation:Three times a number, minus four, is five.4 - 3 w = 53 w - 4 = 53(4 - w) = 53( w - 4) = 5 NEED ASAP PLEASEEExplain why the number 8,000 is a perfect cube.The number 8,000 is a perfect cube because it is the square of the number 20.The number 8,000 is a perfect cube because its cube root is an integer.The number 8,000 is a perfect cube because it is the square root of 64,000,000.The number 8,000 is a perfect cube because its square root is an integer. Based on the reactions:1. 2NO2 (g)N2O4 (g) H1 = - 57.2 kJ2. 2NO(g) + O2 (g)2NO2 (g) H2 = -114.1 kJUse Hess's law to calculate H for:2NO(g) + O2 (g)N2O4 (g) In The Question, I need help with this:For each of the statements, put in the correct properties.Examples: Mr. Arnold drives 130 miles round trip to work 5 days a week. Write and solve an equation to find how many miles he drives in 60 work days. Which of the following is an adjustment allowed by the IRS? I dont understand this it says let a and b be rational numbers A statistics teacher notices a strong, negative, linear association between the number of missing assignments his students had and their report card grades. He computed a correlation coefficient of r=0.9. Which of the following gives the correct value of the coefficient of determination, r2? Im not quite sure how to prove this geometric proof. You are a member of a gang and you have been arrested with another member of your gang. Both of you are confined away from each other and you havenoway of communicating with theothermember. The police do not have enough evidence to convict both of you with major charges and instead offer you and the other member a bargain. Youhave two choices: (a) You can remain silent (b) Or betray the other member and testify that he has committed the crime. E is the midpoint between Dand F. If DE=3x+2, EF=5x, find the value of x. Responses 1 1 15 15 3 3 5 True or false-Normal reaction is the forcethat opposes the force of gravity and acts inthe direction of the force of gravity.O TrueO False Hi I need help with this is it A. B. C. D. And the last multiple choice question says - The cost of 4 adult tickets equals the cost of 3 childrens tickets Which of the following items appears on the income statement?a. Cost of goods sold b. Selling and administrative expenses c. Gross margin. answer wanda wants to find some basic information about her computer, for example, what operating system and how much ram are installed on her computer. where can wanda find this information quickly in windows 10? 34. Summarize: The Black Codes and the Ku Klux Klan were attempts by the South to? Estimate the value of each expression to the nearest integer[tex]\sqrt{x} 3[/tex] Drag the tiles to complete the composition of the functions described The nitrogen in a 30.0 L container at 740 torr and 55C and the hydrogen in a 20.0 L container at 650 torr and 15C are pumped into a 25.0 L container at 32C. What is the final pressure? make 8/3 a mixed number