Student Value Edition for Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133848496
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
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
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".
Chapter 7 Solutions
Student Value Edition for 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
- Write 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_forwardFor this project you will create a program that populates a list of 8 car manufacturers. You can have theuser populate the list or you can have it predefined.(your choice)If you used a predefined list, then ask the user to add a car manufacturer to the list,Example:cars = ['Ford', 'BMW', 'Volvo']print(‘Enter a new Car Manufacturer: ’)cars.append(input())Use the len() function to acquire the length of the list.(this number is used at the end)Example:cars = ['Ford', 'BMW', 'Volvo']length = cars.len()Use the sort() function to sort the list, (Sort before it is displayed at the end)Example:cars = ['Ford', 'BMW', 'Volvo']cars.sort()and displays the contents of the list using a for loop in the following format:The 9 car manufacturers are:BMWFordVolvoarrow_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
- 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:1Output:20Program ended ============================= Example 2:Input:10Output:Index out of range.Program ended what is the solution of this in python programming?arrow_forwardHi, can you do it in PYTHON def delete_item(...): """ param: info_list - a list from which to remove an item param: idx (str) - a string that is expected to contain an integer index of an item in the in_list param: start_idx (int) - an expected starting value for idx (default is 0); gets subtracted from idx for 0-based indexing The function first checks if info_list is empty. The function then calls is_valid_index() to verify that the provided index idx is a valid positive index that can access an element from info_list. On success, the function saves the item from info_list and returns it after it is deleted from info_list. returns: If info_list is empty, return 0. If is_valid_index() returns False, return -1. Otherwise, on success, the function returns the element that was just removed from info_list. Helper functions: - is_valid_index() """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
- In Python: Which of the following set methods removes an element, but does NOT raise an exception if the element is not found? discard( ) remove( ) delete( ) erase( )arrow_forwardIn python which of the following functions as used to add a value to the end of the list? A. add B. append C. push D. endarrow_forwardIf the following is a pointer based list, give the correct commands that change the list from BEFORE to AFTER. BEFORE Plane Bike Pickup Caddy Truck Motorbike Van Ship AFTER Plane Bike Caddy Truck Motorbike Van Scooter Ship Select one: A.insert (5, "Scooter"); delete ("Pickup") B.insert (6, "Scooter"); delete ("Pickup") C.delete ("Scooter"); insert(2, "Pickup") D.delete ("Pickup"); insert (6, "Scooter")arrow_forward
- Python please: Write a program that reads the integers user_index_num and user_element_value as input, and update the list index element with user_element_value. Then output the list. Note: The list given is list = [1,2,3,4]. Use a try block to perform all the statements. Use an except block to catch any IndexError and output an exception message. Use another except block to catch any ValueError caused by invalid input and to output an exception message. Note: Please use list = [1,2,3,4]. IndexError is thrown when an index that is not bound in the list happens. Output wording should match examples below ValueError is thrown when a user enters a value of a different data type than what is defined in the program. Output wording should match example below. Example: If the input of the program is 2 5 the output of the program is [1, 2, 5, 4] Example: If the input of the program is 15 3 the output of the program is Index 15 Error list assignment index out of range Example: If the input of…arrow_forwardWrite the doctests and the body of the push_all function.You must use try/except to deal with StackTypeErrors. from typing import List, TypeVar, Any class EmptyStackError(Exception):"""Exception raised when a pop on an empty stack is attempted.""" class StackTypeError(Exception):"""Exception raised when an item of incorrect type is pushed.""" ################################################################################ TypedStacks###############################################################################class TypedStack:"""A last-in-first-out (LIFO) stack of items of a specific type."""# === Private Attributes ===# _items:# The items stored in this stack. The end of the list represents# the top of the stack.# _type:# The items stored on the stack must be of data type _type_items: List_type: TypeVar def __init__(self, atype: TypeVar) -> None:"""Initialize a new empty stack of atype data."""self._items = []self._type = atype def is_empty(self) -> bool:"""Return whether…arrow_forwardclass SLNode: """ Singly Linked List Node class DO NOT CHANGE THIS CLASS IN ANY WAY """ def __init__(self, value: object, next=None) -> None: self.value = value self.next = next from SLNode import *class SLLException(Exception): """ Custom exception class to be used by Singly Linked List DO NOT CHANGE THIS CLASS IN ANY WAY """ passclass LinkedList: def __init__(self, start_list=None) -> None: """ Initialize new linked list DO NOT CHANGE THIS METHOD IN ANY WAY """ self._head = SLNode(None) # populate SLL with initial values (if provided) # before using this feature, implement insert_back() method if start_list is not None: for value in start_list: self.insert_back(value) def __str__(self) -> str: """ Return content of singly linked list in human-readable form DO NOT CHANGE THIS METHOD IN ANY WAY """ out =…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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