2.14 LAB: Exception handling to detect input string vs. integer   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

Question

2.14 LAB: Exception handling to detect input string vs. integer

 

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
Expand

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Algorithms

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: I am working on the chapter 7 payroll project for cengage and I don't know how to do Holdiay pay for...

A: Payroll register: Payroll register can be defined as the hard copy or a register that records all th...

Q: Ethanol (C₂H₆O) is combusted in air according to the following reaction: C₂H₆O(l) + O₂(g) → CO₂(g) +...

A: Click to see the answer

Q: Mia has ; of a pizza. She divides it equally among 4 people. Which model shows the fraction of a who...

A: Click to see the answer

Q: The table below shows the total cost (TC) and marginal cost (MC) for Choco Lovers, a purely competit...

A: Total cost is the expenditure done by producer in operating business. Marginal cost shows the change...

Q: Modify the class named FormLetterWriter that includes two overloaded methods named displaySalutation...

A: Code in Java : public class FormLetterWriter {       public static void main(String[] args) {       ...

Q: A small toy car costs $3. A large toy car costs 5 times as much as the small one. Aaron wants to buy...

A: Click to see the answer

Q: list of binary values (0 or 1) is used to represent a black-and-white image. Which of the following ...

A: d. A duplicate copy of the data

Q: Transmission Electron Microscopes allow us to see structures at a high resolution. When do we use a ...

A: INTRODUCTION Fluorescence microscope The fluorescence microscope is any microscope that use fluoresc...

Q: A linear revenue function is R=40x   A)what is the slope? B)What is the marginal revenue? C)What...

A: Click to see the answer

Q: Suppose the scores on a grammar quiz are normally distributed with a mean of 76 and a standard devia...

A: Given information: μ=76, σ=8

Q: Label each of the following as an atomic element, a molecular element, or a compound.

A: Atomic element : It is a pure substance consisting of same atoms ( having same number of protons in ...

Q: (minutes) 8 1 6. g(1) (cubic feet per minute) 12.8 15.1 20.5 18.3 22.7 1. Grain is being added to a ...

A: As per bartleby guidelines for more than one question asked only one is to be answered please upload...

Q: An element with mass 310 grams decays by 8.9% per minute. How much of the element is remaining after...

A: Given   mass = 310 gm  Rate = 8.9 %  Time = 19 min

Q: The following monthly data are taken from Ramirez Company at July 31: Sales salaries, $480,000; Offi...

A: 1) Total premium % paid by employees Premium paid by employees Premium paid by employer Employe...

Q: In 2021, OCC Corporation made a charitable donation of $400,000 to the American Red Cross. For the y...

A: Taxable income is the amount of income computed to measure the amount of taxes to be paid to the gov...

Q: As shown in figure a reaction vessel initially contains hydrogen and oxygen. which figure best shows...

A: Second option is correct. This only satisfy the number of molecules in reactant side equal to number...

Q: Match each of the options above to the items below. Iris Pupil Sclera Retina

A: The human eye is a specialized sense organ that reacts to light and is able to visualize images and ...

Q: QuickBooks Online allows the creation of bank rules. In which 3 situations would they be useful?

A: Quickbook is basically an online cloud-based banking software where transactions and statements are ...

Q: A thin rod of length ℓ and uniform charge per unit length λ lies along the x axis, as shown in Figur...

A: Consider an elemental length 'dx' at a distance 'x' from the centre of the wire as shown in the figu...

Q: The given data represent the total compensation for 10 randomly selected CEOs and their company's st...

A: The regression equation is obtained by using EXCEL. The software procedure is given below:In Excel s...

Q: The number of writing instruments in some teachers' desks is displayed in the dot plot. Which is gre...

A: the greatest no. is 12 in the number line as there is a dot on no. 12  mean of this series is = (5+6...

Q: A child weighs 13.5kg and is prescribed a medication for 0.8mg/kg/dose. The stock strength is 10mg/2...

A: A drug refers to the chemical compound that produces a biological effect when administered. It is us...

Q: What does source 4 suggest about Benin relations with the Portuguese?

A: The Portuguese arrived at the shores of Benin in 1489, building up relations that went on for a very...

Q: A random sample of 200 Canadian students was asked about their hand dominance and whether they suffe...

A: Given Information: 

Q: The illustration to the left represents a mixture of xenon ( brown ) and fluorine (green) molecules....

A: Click to see the answer

Q: E1-7 (Algo) Preparing an Income Statement and Inferring Missing Values LO1-1 Bigco Corp. is one of t...

A: Solution:- Preparation of income statement for the year ended June 30, current year as follows under...

Q: The marketing department of a shoe store determined that the number of pairs of shoes sold varies in...

A: The marketing department of a shoe store determined that the number of pairs of shoes sold varies in...

Q: The following graph shows the aggregate demand curve (AD1 ) for this economy before the change in go...

A: The overall demand for all services and goods in an economy is known as "aggregate demand". Consumer...

Q: What is mimicry, and how did it help the salamanders radiate south?

A: Evolution is the alteration of biological populations' heritable traits over centuries. These traits...

Q: Suppose 3.20 g of copper are reacted with excess nitric acid according to the given equation, and 6....

A: Percent yield = Actual yieldTheoretical yield×100%

Q: You're planning on making 8 meatloafs for a party. You go to the store to buy breadcrumbs, and see t...

A: Answer is mentioned below

Q: The average number of employees that call in sick for the day over the course of a year is 25. The ...

A: Sample mean x̄ = ( Σxi )/n  = (25 + 10 + 16 + 39+ 27 + 25 + 32 + 25 + 25 + 22 + 28 + 14)/12  = 288/1...

Q: 4. Felix and Oscar applied for the same credit card from the same bank. The bank checked both of the...

A: Felix and Oscar applied for the same credit card from the same bank.The bank checked both their FICO...

Q: Pseudocode for the mystery algorithm 1. input two integers: a,b 2. initialize the value of x to a ...

A: Algorithm:- A technique for addressing a well-defined computing issue is known as an algorithm. All ...

Q: A ball is thrown into the air by a baby alien on a planet in the system of Alpha Centauri with a vel...

A: Click to see the answer

Q: Suppose there is an infectious disease at a party. How could doctors tell if the disease was foodbor...

A: Infectious diseases are disorders caused by organisms such as bacteria, viruses,  fungi or parasites...

Q: The following table lists the joint probabilities associated with smoking and lung disease among 60-...

A: Click to see the answer

Q: Cody wants to compare how students in two grades use the school library. For one week, he records th...

A: Click to see the answer

Q: In Raiders of the Lost Ark, Indiana Jones tried to remove a gold idol from a booby-trapped pedestal....

A: Given : Mass of gold idol = 2.00 Kg And density of sand = 3.00 g/cm3 = 3.00 Kg/L                    ...

Q: Assign point_dist with the distance between point (x1, y1) and point (x2, y2). The calculation is: D...

A: Required: 1.18.1 Assign point_dist with the distance between point (x1, y1) and point (x2, y2). The ...

Q: 7. Short-run supply and long-run equilibrium Consider the competitive market for copper. Assume tha...

A: Click to see the answer

Q: AMP Corporation (calendar-year-end) has 2020 taxable income of $1,900,000 for purposes of computing ...

A: Qualified assets under section 179 is : Machinery = $ 1360000 Computer equipment = $ 400000

Q: A robot spacecraft returned samples from the planetesimal 98765 ALEKS, located in the outer Solar Sy...

A: The average atomic weight of the Molybdenum isotopes can be calculated as

Q: Joe is using the function E = 1.89x + 2.89y to minimize his expenses when selling markers and eraser...

A: If you like the solution then please give it a thumbs up.... The Answer is:           Result = 9.45 ...

Q: A 132 g sample of a nonvolatile compound was dissolved in 4.30 mol of cyclohexane (P° = 100.0 mmHg)....

A: Given data: The mass of the sample (solute)=132 g. The moles of cyclohexane (solvent) n2=4.30 mol. T...

Q: Joe often lies and steals, and he is very aggressive and violent. He behaves badly around others and...

A: Mental health reflects a state of subjective well-being in several life domains including emotional,...

Q: You are planning for a very early retirement. You would like to retire at age 40 and have enough mon...

A: Hi There, thanks for posting the question. But as per Q&A guidelines, we must answer the first t...

Q: What is the minimum cost in dollars for a fair to be included in the highest 9% of domestic airfares...

A: Provided information is,  The mean cost of domestic airfares in the United States rose to an all-tim...

Q: Understanding Cultural Connections What does the reader learn about the Maasai people from "The Begi...

A: (Please note: questions based on sources should be posted along with the source) The Maasai people a...

Q: A solution of lead sulfate (PbSO4) contains 0.425 g of lead sulfate in 100.0 g of water.  What is th...

A: Given that : Mass of PbSO4 = 0.425 g Mass of water = 100.0g Total mass of the solution = 0.425g + 10...