Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7, Problem 5MC
This will happen if you try to use an index that is out of range for a list
a. A valuError exception will occur.
b. An IndexError exception will occur.
c. The list will be erased and the
d. Nothing—the invalid index will be ignored.
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:11
Students have asked these similar questions
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 program continues running at the next statement.
python exercise:
Write a Python function called calculate_average that takes a list of numbers as input and returns the average of the numbers in the list. If the input list is empty, the function should raise an EmptyListError exception.
Handle the case where the input list is empty by raising a custom EmptyListError exception. This exception should have an error message that says "Cannot calculate average of an empty list".
In Python:
If you call the index method to locate an item in a list and the item is not found, this happens
A ValueError exception is thrown
An InvalidIndex exception is thrown
The method returns -1
Nothing happens, The method does not return anything and the program continues execution
Chapter 7 Solutions
Starting Out with Python (3rd Edition)
Ch. 7.2 - What will the following code display? numbers =...Ch. 7.2 - Prob. 2CPCh. 7.2 - Prob. 3CPCh. 7.2 - Prob. 4CPCh. 7.2 - Prob. 5CPCh. 7.2 - Prob. 6CPCh. 7.2 - Prob. 7CPCh. 7.2 - Prob. 8CPCh. 7.3 - Prob. 9CPCh. 7.3 - Prob. 10CP
Ch. 7.3 - Prob. 11CPCh. 7.3 - Prob. 12CPCh. 7.3 - Prob. 13CPCh. 7.4 - What will the following code display? names =...Ch. 7.5 - Prob. 15CPCh. 7.5 - Prob. 16CPCh. 7.5 - Prob. 17CPCh. 7.5 - Prob. 18CPCh. 7.8 - Prob. 19CPCh. 7.8 - Prob. 20CPCh. 7.8 - Write a set of nested loops that display the...Ch. 7.9 - Prob. 22CPCh. 7.9 - Prob. 23CPCh. 7.9 - Prob. 24CPCh. 7.9 - Prob. 25CPCh. 7 - This term refers to an individual item in a list....Ch. 7 - This is a number that identifies an item in a...Ch. 7 - Prob. 3MCCh. 7 - This is the last index in a list. a. 1 b. 99 c. 0...Ch. 7 - This will happen if you try to use an index that...Ch. 7 - This function returns the length of a list. a....Ch. 7 - When the operator's left operand is a list and...Ch. 7 - This list method adds an item to the end of an...Ch. 7 - This removes an item at a specific index in a...Ch. 7 - Prob. 10MCCh. 7 - If you call the index method to locate an item in...Ch. 7 - Prob. 12MCCh. 7 - This file object method returns a list containing...Ch. 7 - Which of the following statement creates a tuple?...Ch. 7 - Prob. 1TFCh. 7 - Prob. 2TFCh. 7 - Prob. 3TFCh. 7 - Prob. 4TFCh. 7 - A file object's writelines method automatically...Ch. 7 - You can use the + operator to concatenate two...Ch. 7 - Prob. 7TFCh. 7 - You can remove an element from a tuple by calling...Ch. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - What will the following code display? values = [2,...Ch. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 1AWCh. 7 - Prob. 2AWCh. 7 - Prob. 3AWCh. 7 - Prob. 4AWCh. 7 - Write a function that accepts a list as an...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Total Sales Design a program that asks the user to...Ch. 7 - Prob. 2PECh. 7 - Rainfall Statistics Design a program that lets the...Ch. 7 - Prob. 4PECh. 7 - Prob. 5PECh. 7 - Larger Than n In a program, write a function that...Ch. 7 - Drivers License Exam The local driver s license...Ch. 7 - Name Search If you have downloaded the source code...Ch. 7 - Prob. 9PECh. 7 - World Series Champions If you have downloaded the...Ch. 7 - Prob. 11PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
An interpreter is a program that both translates and executes the instructions in a high-level language program...
Starting out with Visual C# (4th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Write a do-whi1e loop that asks the user to enter two numbers. The numbers should be added and the sum displaye...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Using examples, illustrate the different types of adaptor needed to support sequential composition, hierarchica...
Software Engineering (10th Edition)
Car Loan If A dollars are borrowed at r interest compounded monthly to purchase a car with monthly payments for...
Introduction To Programming Using Visual Basic (11th Edition)
(Frequency of characters) Write a program that prompts the user to enter the name of an ASCII text file and dis...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Task 6 Given 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: 1 Output: 20 Program ended Example 2: Input: 10 Output: Index out of range. Program endedarrow_forwardMust show it in Python: Please show step by step with comments. Please show it in simplest form. Input and Output must match with the Question Please go through the Question very carefully.arrow_forwardIf t is a list with exactly one element in python, what is the name of the exception that will be thrown if you try to access t[1]? NameError IndexError ValueError KeyErrorarrow_forward
- Invalid indexes in slicing expressions can produce an ‘out of bound’ exception.True or Flasearrow_forwardIf d is an empty dict in python, what is the name of the exception that will be thrown if you try to access d[1] ? ValueError NameError IndexError KeyErrorarrow_forwardA Lo Shu Magic Square is a grid with 3 rows and 3 columns. The Lo Shu Magic Square has these properties:-A grid that contains the numbers 1-9.-The sum of each row, each column, and each diagonal all adding up to the same number.In Python create a program simulatimg the magic square using a two-dimensional list.Additional requirements: -It must throw an exception if any character other than 1 – 9 is selected.-The program needs to give an message explaining that wrong input has been provided.-The program should prompt the user until the condition has been satisfied. It should prompt the user to enter a number from 1-9.-The program can only use each number once.-When the program starts, it should explain how to play the game. Those who have never heard of it should be able to play. The directions should be clear.-Show an example of a Lo Shu Magic Square after each game.-The program should allow users to play the game until they choose to quit.It also must keep track of wins and…arrow_forward
- What happens if an exception is thrown, but not caught?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_forwardUSING PYTHON: Given a list of 10 names, complete the program that outputs the name specified by the list index entered by the user. Use a try block to output the name and an except block to catch any IndexError. Output the message from the exception object if an IndexError is caught. Output the first element in the list if the invalid index is negative or the last element if the invalid index is positive. Note: Python allows using a negative index to access a list, as long as the magnitude of the index is smaller than the size of the list. Ex: If the input of the program is: 5 the program outputs: Name: Jane Ex: If the input of the program is: 12 the program outputs: Exception! list index out of range The closest name is: Johnny Ex: If the input of the program is: -2 the program outputs: Name: Tyrese Ex: If the input of the program is: -15 the program outputs: Exception! list index out of range The closest name is: Ryley CODE: names = ['Ryley', 'Edan', 'Reagan', 'Henry', 'Caius',…arrow_forward
- If an exception is raised and the program does not handle it with a try/exceptstatement, what happens?arrow_forwardWrite a python program that takes two lists as input from the user, multiplies the index-wise elements of the two lists, and adds it to a new variable. While doing the program you should handle the following exceptions: Return an exception if an element in a list is not a number stating “The list has some non-number values”. Return an exception if there is an index out of bound stating “Index out of bound”. ============================= Example 1:Input:list_one = [1, a, 2, 4]list_two =[5, 6, 7, 8]Output:The list has some non number values ================= Example 2:Input:list_one=[1, 2, 3, 4, 5]list_two=[1, 2, 3, 4]Output:Index out of bound ================= Example 3:Input:list_one=[1,2,3,4]list_two=[5,6,7,8]Output:70arrow_forwardWrite a python program that takes two lists as input from the user, multiplies the index wise elements of the two lists and adds it to a new variable. While doing the program you should handle the following exceptions: Return an exception if an element in a list is not a number stating “The list has some non number values”. Return an exception if there is an index out of bound stating “Index out of bound”. ============================= Example 1:Input:list_one = [1, a, 2, 4]list_two =[5, 6, 7, 8]Output:The list has some non number values ================= Example 2:Input:list_one=[1, 2, 3, 4, 5]list_two=[1, 2, 3, 4]Output:Index out of bound ================= Example 3:Input:list_one=[1,2,3,4]list_two=[5,6,7,8]Output:70 what's the solution to this in python programming?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Linux - Tutorial for Beginners in 13 MINUTES! [ UPDATED ]; Author: bai;https://www.youtube.com/watch?v=BMGixkvJ-6w;License: Standard YouTube License, CC-BY
What is Linux?; Author: Techquickie;https://www.youtube.com/watch?v=zA3vmx0GaO8;License: Standard YouTube License, CC-BY
Introduction to Linux and Basic Linux Commands for Beginners; Author: sakitech;https://www.youtube.com/watch?v=IVquJh3DXUA;License: Standard Youtube License