Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8, Problem 3MC
This will happen if you try to use an index that is out of range for a string.
a. A ValueError exception will occur.
b. An IndexError exception will occur.
c. The string will be erased and the
d. Nothing—the invalid index will be ignored.
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:24
Students have asked these similar questions
If 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
KeyError
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 an exception is raised and the program does not handle it with a try/exceptstatement, what happens?
Chapter 8 Solutions
Starting Out with Python (4th Edition)
Ch. 8.1 - Assume the variable name references a string....Ch. 8.1 - What is the index of the first character in a...Ch. 8.1 - If a string has 10 characters, what is the index...Ch. 8.1 - Prob. 4CPCh. 8.1 - Prob. 5CPCh. 8.1 - Prob. 6CPCh. 8.2 - Prob. 7CPCh. 8.2 - Prob. 8CPCh. 8.2 - Prob. 9CPCh. 8.2 - What will the following code display? mystring =...
Ch. 8.3 - Prob. 11CPCh. 8.3 - Prob. 12CPCh. 8.3 - Write an if statement that displays Digit" if the...Ch. 8.3 - What is the output of the following code? ch = 'a'...Ch. 8.3 - Write a loop that asks the user Do you want to...Ch. 8.3 - Prob. 16CPCh. 8.3 - Write a loop that counts the number of uppercase...Ch. 8.3 - Assume the following statement appears in a...Ch. 8.3 - Assume the following statement appears in a...Ch. 8 - This is the first index in a string. a. 1 b. 1 c....Ch. 8 - This is the last index in a string. a. 1 b. 99 c....Ch. 8 - This will happen if you try to use an index that...Ch. 8 - This function returns the length of a string. a....Ch. 8 - This string method returns a copy of the string...Ch. 8 - This string method returns the lowest index in the...Ch. 8 - This operator determines whether one string is...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns a copy of the string...Ch. 8 - Once a string is created, it cannot be changed.Ch. 8 - You can use the for loop to iterate over the...Ch. 8 - The isupper method converts a string to all...Ch. 8 - The repetition operator () works with strings as...Ch. 8 - Prob. 5TFCh. 8 - What does the following code display? mystr =...Ch. 8 - What does the following code display? mystr =...Ch. 8 - What will the following code display? mystring =...Ch. 8 - Prob. 4SACh. 8 - What does the following code display? name = 'joe'...Ch. 8 - Assume choice references a string. The following...Ch. 8 - Write a loop that counts the number of space...Ch. 8 - Write a loop that counts the number of digits that...Ch. 8 - Write a loop that counts the number of lowercase...Ch. 8 - Write a function that accepts a string as an...Ch. 8 - Prob. 6AWCh. 8 - Write a function that accepts a string as an...Ch. 8 - Assume mystrinc references a string. Write a...Ch. 8 - Assume mystring references a string. Write a...Ch. 8 - Look at the following statement: mystring =...Ch. 8 - Initials Write a program that gets a string...Ch. 8 - Sum of Digits in a String Write a program that...Ch. 8 - Date Printer Write a program that reads a string...Ch. 8 - Prob. 4PECh. 8 - Alphabetic Telephone Number Translator Many...Ch. 8 - Average Number of Words If you have downloaded the...Ch. 8 - If you have downloaded the source code you will...Ch. 8 - Sentence Capitalizer Write a program with a...Ch. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Word Separator Write a program that accepts as...Ch. 8 - Pig Latin Write a program that accepts a sentence...Ch. 8 - PowerBall Lottery To play the PowerBall lottery,...Ch. 8 - Gas Prices In the student sample program files for...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a function called r to remove an e from a linked list. The sole argument to the procedure should be a poi...
Programming in C
Describe the purpose of the access key attribute and how it supports accessibility.
Web Development and Design Foundations with HTML5 (8th Edition)
Write a program that inputs a date (for example, July 4, 2008) and outputs the day of the week that corresponds...
Problem Solving with C++ (9th Edition)
T F A function may return a structure.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Which of the following activities do you expect to be performance oriented and which are simulation oriented? a...
Computer Science: An Overview (12th Edition)
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th 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
- What happens if an exception is thrown, but not caught?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_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
- 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_forwardjava program that Creates an INDEXCEPTION value of the unique vowels and unique consonants that the name that was given to you can create.Input: A string of the name that was GIVEN TO YOU. CASE SENSITIVE.Process1: For every unique vowel of a name, you need to get the first index of that vowel from the original string. 2: For each vowel index you get from step 1, you will get the unique consonant from that position. if the index is out of scope of the consonant array, ignore that vowel index. 3: For each unique consonant that you get from step 2, you need to get the first index of that consonant from the original string. 4: Get the value of indexception by adding all index you get from step 3.OutputTO BE DISPLAYED- 2 lists that consists of unique vowels and unique consonants- The vowel, the vowel index, the consonant, the consonant indexFINAL OUTPUT- The total indexception value of the name that was given to you.arrow_forwardInvalid indexes in slicing expressions can produce an ‘out of bound’ exception.True or Flasearrow_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_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_forwardplease help me using pythonarrow_forward
- Subject: Object Oriented PrgrammingLanguage: Java ProgramTopic: Exception (SEE ATTACHED PHOTO FOR THE PROBLEM)arrow_forward# Split input into 2 parts: name and age parts = input().split() name = parts[0] while name != '-1': # Insert try/except blocks to catch the exception. try: age = int(parts[1]) + 1 # printing name and age print('{} {}'.format(name, age)) except ValueError: # printing name and age as 0 print('{} {}'.format(name, 0)) # Get next line parts = input().split() name = parts[0]arrow_forward1. Hotel Reservation System Note: Implement OOP Concepts(Class, Object, Inheritance, Information Hiding, etc)2. The application will ask the user to choose between: a. View all Reservations b. Make Reservation c. Delete Reservation d. Generate Report e. Exit Note: add an appropriate exception.3. If Make Reservation is selected, the application will ask the user to input the following: (Name, Date, Time, No. of Adults, No. of Children) then save the data to hotel.txt Including the entry no. and total. Note: Adult = P500/head and Child = P300/head.4. If View all Reservations is selected, it must display the following: (Entry#, Name, Date, Time, Adults, Children)5. If Delete Reservation is selected, an entry from hotel.txt should be deleted and adjust the entry number.6. If Generate Report is selected, it must display the following: (Entry#,Name,Date,Time,Adults,Children,subTotal and the grand total)7. If Exit, print “Thank You!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