Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6.4, Problem 21CP
What type of exception does a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What type of exception does a program raise when it tries to open a nonexistent file?
What are some common techniques for handling exceptions when reading a file?
What is the reason for scheduling a procedure with an exception?
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
In the following table, fill in the expected values returned by the ToString function when specific numeric val...
Starting Out With Visual Basic (8th 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
- When a program is finished using a file, it should do this.a. erase the fileb. close the filec. throw an exceptiond. reset the read positionarrow_forwardQUESTION 7 An unchecked exception is an exception that a programmer should be able to anticipate and appropriately handle. O True O False QUESTION 8 A file is a persistent data structure - data written to a file exists even after your program terminates. O True Falsearrow_forwardIf a function throws an exception, how does it specify that exception?arrow_forward
- Describe the key principles of handling exceptions when reading or writing to files in a programming language of your choice.arrow_forwardHow can developers determine the appropriate level of granularity for catching exceptions when working with files?arrow_forwardFocus on Basic file operations, exception handling. Save a copy of the file module6data.txt (Below) Write a program that will Open the file module6data.txt Create a second file named processed. txt Read the numbers from the first file one at a time. For each number write into second file, if possible, its Square Square root iii. Reciprocal (1/number)use a math module function for the square root. use exception handling to trap possible errors. Report the number of items in the original file and the number that were successfully stored in the second file. Report the number of each type of error: ValueError, ZeroDivisionError, TypeError 26 O 76 -91 85 -44 85 -95 -34 83 -64 -76 -41 89 0 83 -99 -69 8 -79 0 -32 -49 -89 85 79 -28 56 19 -93 -21 -23 82 51 -80 l 62 -78 -8 71 28 -73 0 -45 -73 28 -5 O -70 63 -36 -72 0 -76 -24 -59 0 -54 83 35 -3 88 -14 29 -35 17 27 -61 -42 49 83 38 79 -80 33 8 41 96 -94 46 71 8 76 -63 -36 93 -82 -68 -20 69 -57 -84 -29 -17 77 36 -89 -94 62 10 -69 -43 Use…arrow_forward
- Assignment: Exception Handling and Text 10 Problem Statement: Write a program that reads a file named "input.txt" that contains integers separated by whitespace (space, tab, or newline). The program should calculate the sum of all the integers in the file, ignoring any non-numeric values. Requirements: The program should define a class named "FileSumCalculator". The class should have a method named "calculateSum" that takes a file path as a parameter and returns the sum of all the integers in the file. The method should handle any exceptions that might occur during the file reading and sum calculation. The program should print the sum of all the integers in the file to the console. Examples: 1. If the contents of the "input.txt" file are: 123 4 five 67 The program should print: Sum: 23arrow_forwardIn pythonarrow_forwardIn Python IDLE write a program that writes a series of random numbers to file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file will hold This exercise assumes you have completed you have completed program exercise 7 random number file writer. Write another program that reads the random numbers from the file, displayed the numbers, then displays the following data: Exception Handling: Both programs should use Try and Except Clauses to handle IOError, ValueError, and unspecified error exceptions. Be sure to test your programs for invalid cases. For example , try running the second program to read the file when it doesn’t exist or manually put bad data in the file and see what happens.arrow_forward
- fname=input("Enter a file's name: ") with open(fname, 'r') as fh: for line in fh: print(line) Criteria to complete the above snippet: 1)Code will keep looping until the user enters an existing file name. 2) need to use exception with [Error 7] as the message 3)need to catch the exception so the program does not crash 4) close the program after reading contents of the file and print contents to the screen 5)create a test filearrow_forwardMusic App 1. practise file I/O and exception handling; 2. practise String processing. Aim: Task: Create a Java application that transcripts a simple song score sheet. The program asks user for filename of a text file that contains a simple song score sheet in this format: Sample song score sheet 1, song1.txt: #simple song with assumed time signature = 4 d1mls202s 1mld2o2 d1rimlfls 301s1f1m1rld4 Lines beginning with a hash #' is a comment line. A song contains one or more lines of musical notes, d, r, m, f, s, l, tand also o meaning "Off" or rest. Each single character note is followed by a single digit integer in [1 – 4], denoting the duration of the note in number of beats. After transcription, the program outputs the melody on the screen as well as to another text file: Melody output 1, on screen AND in melody_song1.txt: #simple song with assumed time signature Do Me So- Off- So Me Do Re Me Fa| So-- Off = 4 Do- Off- | So Fa Me Re Do--- | The default time signature is 4 beats per…arrow_forwardIf a file does not exist and a program attempts to open it in append mode, what happens?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License