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
MyLab Programming with Pearson eText -- Access Code Card -- for Starting Out with Python (My Programming Lab)
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 happens if an exception is thrown, but not caught?arrow_forwardIf an exception is thrown, how do you get out of break mode?arrow_forwardh. What happens when both the minimize box and maximize box property are set to false? This situation shows an error This situation shows an exception Both are removed from the title bar Both are disabledarrow_forward
- in 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_forwardThe return Or the throw function sometimes returns a random number and throws anither number as an exception. Write a code that will print out the number that the returnorthrow function gives back even if it throws an exception.arrow_forwardWhat happens when an exception occurs in a method but it is not caught inside the method? The method exits immediately. The exception is passed to the caller. An exception is thrown. All of the other answers are correct.arrow_forward
- C++ You did this way back in Unit 1! But now all of your RomanNumber code is wrapped up in a class, so the "main" program is short and sweet. As before, write a program that accepts entries from the user. If it's an integer, convert to Roman Number and display. If it's a Roman Number, convert to integer and display. If it's neither, thrown an exception and continue to process The action to take here will be to display an error message If the entry is 0 or O (The digit 0 (zero) or the letter O) exit and state how many conversions were done of each type (integer to Roman and Roman to integer) and how many exceptions were thrown. As I said, the main program will be short and sweet. Provide your .cpp code and a screen shot of your program in action. Enter twelve conversions - four integer to Roman, four Roman to integer, and two of each in which the input is invalid so that I can see the exceptions. The thirteenth and final entry will be 0 or O.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_forwardPYTHON: A pedometer treats walking 2,000 steps as walking 1 mile. Write a steps_to_miles() function that takes the number of steps as a parameter and returns the miles walked. The steps_to_miles() function throws a ValueError object with the message "Exception: Negative step count entered." when the number of steps is negative. Complete the main() program that reads the number of steps from a user, calls the steps_to_miles() function, and outputs the returned value from the steps_to_miles() function. Use a try-except block to catch any ValueError object thrown by the steps_to_miles() function and output the exception message. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print('{:.2f}'.format(your_value)) Ex: If the input of the program is: 5345 the output of the program is: 2.67 Ex: If the input of the program is: -3850 the output of the program is: Exception: Negative step count entered.arrow_forward
- What is the value of the expression max().) O None It raises a ValueError exception. O It raises an IndexError exception.arrow_forwardThis Phyton: In this lab, you will write a program that reads integers from a file “data.txt” into a list, print the list and the sum of the numbers in the list. The file contains one integer per line. You are not required to do any exception handling. Your program should not prompt the user for any input. The input file is “data.txt”. First, create a file “data.txt” and put the numbers add the numbers 3, 1, 5, 2 into it, one number per line as shown in the sample “data.txt” file below. Sample “data.txt” file 3 1 5 2 Then, write the following functions: read_numbers(filename) Read numbers from the given file and return a list of contains the numbers from the file. compute_sum(numbers) Compute the sum of the given the list numbers. Do not use the built-in sum function. main() Read numbers from the file “data.txt”, print the list, and compute the sum and print it. Main will use the two functions above to get the job done. Sample run: [3, 1, 5,…arrow_forwardIf an object cannot be found, it is generally better to throw an exception than return null. True Falsearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning