Concept explainers
If you call the index method to locate an item in a list and the item is not found, this happens.
a. A ValueError exception is raised.
b. An InvalidIndex exception is raised.
c. The method returns -1.
d. Nothing happens. The
Learn your wayIncludes step-by-step video
Chapter 7 Solutions
Starting Out with Python Plus MyLab Programming with Pearson eText -- Access Card Package (4th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
C How to Program (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- What results are feasible if an exception is raised outside of a try block?arrow_forwardGiven a list named my_list. my_list=[10,20,30,40,60,100,2,5] Write a python program that takes the position as an input from the user and prints the element of that position from the list. If the user’s input position is not in the range, return an exception stating “Index out of range”. Make sure your program always prints “Program ended” at the end, no matter what happens. ============================= Hint: Use finally block ============================= Example 1:Input:1Output:20Program ended ============================= Example 2:Input:10Output:Index out of range.Program ended what is the solution of this in python programming?arrow_forwardWrite a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application will display messages indicating whether the names were among the most popular. your program should read the files into separate lists for boys and girls names the program should accept either a girl name or a boy name or both, entry of a NULL i.e. just pressing the "enter key" results in no search for that entry the program must continue to run until told to stop by the person running the program using any method of your choice report on the success or not of each attempt to locate a name in the popular names filesarrow_forward
- If an exception is thrown outside a try block, what are the probable outcomes?arrow_forwardin pytrhon programming language, What happens when an unhandled exception occurs? The finally clause executes, and the code finishes. The finally clause executes, and the code returns -1. The finally clause executes, and then the exception is re-raised. The finally clause executes, and then runs the try block again.arrow_forwardIf an exception is raised and the program does not handle it with a try/exceptstatement, what happens?arrow_forward
- 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 code name = ()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]) + 1print('{} {}'.format(name, age))# Get next lineparts = input().split()name = parts[0]arrow_forwardA thrown exception may contain more information about what caused the exception. True or Falsearrow_forwardFinally, in a try/except statement, the finally suite runs only if the try suite's statements do not throw any exceptions.True or False?arrow_forward
- What happens to a local reference in a try block when that block throws an Exception?arrow_forwardWhen the user is done the program should calculate the MPG by calling GetMPG, catching the exception if the user did not enter any values. Then it should show the result. Stream Errors coutarrow_forwardWhat is printed to the console when the code that follows is executed? ArrayList<String> passwords = new ArrayList<>(); passwords.add("akjdk12"); passwords.add("buujl32"); passwords.add("chrcl92"); passwords.add("nnnii87"); passwords.set(2, "cb2kr45"); passwords.remove("akjdk12"); System.out.println(passwords.get(1));arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning