Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 6, Problem 15MC
Program Description Answer
The “try/except” statement helps to give a response to the exception that occurs in the
Hence, the correct answer is option “B”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
To throw an exception, what form of statement is
used?
When will be the else part of
try-except-else be executed?
a. None of these
b. when no exception
occurs
c. always
d. when an exception
occurs
You write this statement to respond to exceptions.a. run/handleb. try/exceptc. try/handled. attempt/except
Chapter 6 Solutions
Starting Out with Python (4th Edition)
Ch. 6.1 - What is an output file?Ch. 6.1 - What is an input file?Ch. 6.1 - What three steps must be taken by a program when...Ch. 6.1 - Prob. 4CPCh. 6.1 - Prob. 5CPCh. 6.1 - When writing a program that performs an operation...Ch. 6.1 - If a file already exists, what happens to it if...Ch. 6.1 - What is the purpose of opening a file?Ch. 6.1 - What is the purpose of closing a file?Ch. 6.1 - Prob. 10CP
Ch. 6.1 - In what mode do you open a file if you want to...Ch. 6.2 - Write a short program that uses a for loop to...Ch. 6.2 - Prob. 13CPCh. 6.2 - Assume the file data.txt exists and contains...Ch. 6.2 - Prob. 15CPCh. 6.3 - Prob. 16CPCh. 6.3 - Prob. 17CPCh. 6.3 - Prob. 18CPCh. 6.4 - Prob. 19CPCh. 6.4 - Prob. 20CPCh. 6.4 - What type of exception does a program raise when...Ch. 6.4 - Prob. 22CPCh. 6 - A file that data is written to is known as...Ch. 6 - A file that data is written to is known as...Ch. 6 - Before a file can be used by a program, it must be...Ch. 6 - When a program is finished using a file, it should...Ch. 6 - The contents of this type of file can be viewed in...Ch. 6 - This type of file contains data that has not been...Ch. 6 - When working with this type of file, you access...Ch. 6 - When working with this type of file, you can jump...Ch. 6 - This is a small holding section" in memory that...Ch. 6 - This marks the location of the next item that will...Ch. 6 - When a file is opened in this mode, data will be...Ch. 6 - This is a single piece of data within a record. a....Ch. 6 - Prob. 13MCCh. 6 - Prob. 14MCCh. 6 - Prob. 15MCCh. 6 - When working with a sequential access file, you...Ch. 6 - When you open a file that file already exists on...Ch. 6 - The process of opening a file is only necessary...Ch. 6 - Prob. 4TFCh. 6 - When a file that already exists is opened in...Ch. 6 - Prob. 6TFCh. 6 - You can have more than one except clause in a...Ch. 6 - Prob. 8TFCh. 6 - Prob. 9TFCh. 6 - Describe the three steps that must be taken when a...Ch. 6 - Why should a program close a file when it's...Ch. 6 - What is a read position? where is the read...Ch. 6 - If an existing file is opened in append mode, What...Ch. 6 - If a file does not exist and a program attempts to...Ch. 6 - Write a program that opens an output file with the...Ch. 6 - Write a program that opens the my_name.txt file...Ch. 6 - Write code that does the following: opens an...Ch. 6 - Prob. 4AWCh. 6 - Modify the code that you wrote in problem 4 so it...Ch. 6 - Write code that opens an output file with the...Ch. 6 - A file exists on the disk named students. txt. The...Ch. 6 - A file exists on the disk named students txt. The...Ch. 6 - Prob. 9AWCh. 6 - Prob. 10AWCh. 6 - File Display Assume a file containing a series of...Ch. 6 - File Head Display Write a program that asks the...Ch. 6 - Line Numbers Write a program that asks the user...Ch. 6 - Item Counter Assume a file containing a series of...Ch. 6 - Sum of Numbers Assume a file containing a series...Ch. 6 - Average of Numbers Assume a file containing a...Ch. 6 - Random Number File Writer Write a program that...Ch. 6 - Random Number File Reader This exercise assumes...Ch. 6 - Prob. 9PECh. 6 - Golf Scores The Springfork Amateur Golf Club has a...Ch. 6 - Personal Web Page Generator Write a program that...Ch. 6 - Average Steps Taken A Personal Fitness Tracker is...
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
- Finally, in a try/except statement, the finally suite runs only if no exceptions are thrown by the try suite's statements. False or Truearrow_forwardYou can catch any exception by writing one except clause.True or Falsearrow_forwardIf an exception is thrown, how do you get out of break mode?arrow_forward
- Put unused code in the right orderarrow_forwardIf you do not handle an exception, it is ignored by the Python interpreter, and the program continues to execute.True or Falsearrow_forwardDirection:Analyze the given problem and create a java program using exception. Problem:Create a program that will accept any real number then,converts the number to fractional number,and multiply the value by 9.arrow_forward
- If an exception is raised and the program does not handle it with a try/exceptstatement, what happens?arrow_forwardJava Exceptions: Your parents gave you an emergency cash card that has 2 restrictions: it can't be used to purchase alcohol, and the purchase price must be less than $100. Write a program segment in main() that will read 2 inputs from the user describing a purchase you are trying to make using the cash card: the item purchased (eg runners) and the purchase price (eg 79.99). Your code must check for the 2 restrictions mentioned above and generate exceptions if either one of them occurs (InvalidItemException or InvalidPurchasePriceException. Assume that these have already been coded so you don't need to write them). Your code must also deal with each exception by writing out an appropriate (specific) message stating what the problem is. If there is no problem your code should generate a "Payment accepted" message.arrow_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
- 3. The program shall: generate a random number from 1 to 50 for a player to guess; • display a message that indicates whether the player's guess is correct, too low, or too high; and prompt the user to keep on guessing until the correct value is entered 4. Create a try-catch structure that will handle two (2) exceptions. These are when the user inputs the following: a number that is out of range (1- 50) a letter or any non-numeric character 5. Prompt the user so that he can guess again if an exception is thrown. 6. Display the number of total guesses. Note: An invalid input (when an exception is thrown) is not considered a valid guess or attempt. Sample Output: Guess a number from 1 to 501 30 Too high. Try again. 15 Too high. Try again. 10 Too high. Try again. Too lov. Try again. gverty Invalid input. Guess a nunber from 1 to 501 51 Out of range Guess a nuaber from 1 to 501 Too lov. Try again. 8 Too lov. Try again. You got it in 7 atteapt (s)!arrow_forwardHow can an exception be thrown manually by a programmer?arrow_forwardThe finally suite in a try/except statement executes only if no exceptions are raised by statements in the try suite.True or Falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,