Home / Expert Answers / Computer Science / python-please-the-given-program-reads-a-list-of-single-word-first-names-and-ages-ending-with-1-pa341

(Solved): python please The given program reads a list of single-word first names and ages (ending with -1), ...



python please

The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incre

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


We have an Answer from Expert

View Expert Answer

Expert Answer


Python Code:- def sort_name_by_age(list_of_names_and_age): # function to sort by age list_of_names_and_age.sort(key=lambda x: x[1]) # sort by age using lambda function as key = x[1] represents sort by element at index 1 return list_of_nam
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe