• Home
  • Textbooks
  • Starting Out with Python
  • Files and Exceptions

Starting Out with Python

Tony Gaddis

Chapter 6

Files and Exceptions - all with Video Answers

Educators


Chapter Questions

01:07

Problem 1

What is an output file?

Sanchit Jain
Sanchit Jain
Numerade Educator
01:02

Problem 2

What is an input file?

Sanchit Jain
Sanchit Jain
Numerade Educator
01:10

Problem 3

What three steps must be taken by a program when it uses a file?

Adam Conner
Adam Conner
Numerade Educator
03:45

Problem 4

In general, what are the two types of files? What is the difference between these two types of files?

Foster Wisusik
Foster Wisusik
Numerade Educator
03:45

Problem 5

What are the two types of file access? What is the difference between these two?

Foster Wisusik
Foster Wisusik
Numerade Educator
02:01

Problem 6

When writing a program that performs an operation on a file, what two file-associated names do you have to work with in your code?

Adam Conner
Adam Conner
Numerade Educator
01:43

Problem 7

If a file already exists, what happens to it if you try to open it as an output file (using the 'w' mode)?

Adam Conner
Adam Conner
Numerade Educator
03:21

Problem 8

What is the purpose of opening a file?

RO
Reynald Oliveria
Numerade Educator
03:21

Problem 9

What is the purpose of closing a file?

RO
Reynald Oliveria
Numerade Educator
01:56

Problem 10

What is a file’s read position? Initially, where is the read position when an input file is opened?

Rashmi Sinha
Rashmi Sinha
Numerade Educator
02:50

Problem 11

In what mode do you open a file if you want to write data to it, but you do not want to erase the file’s existing contents? When you write data to such a file, to what part of the file is the data written?

Foster Wisusik
Foster Wisusik
Numerade Educator
01:37

Problem 12

Write a short program that uses a for loop to write the numbers 1 through 10 to a file.

Willis James
Willis James
Numerade Educator
01:53

Problem 13

What does it mean when the readline method returns an empty string?

Foster Wisusik
Foster Wisusik
Numerade Educator
03:29

Problem 14

Assume the file data.txt exists and contains several lines of text. Write a short program using the while loop that displays each line in the file.

James Kiss
James Kiss
Numerade Educator
02:41

Problem 15

Revise the program that you wrote for Checkpoint 6.14 to use the for loop instead of the while loop.

Ren Jie Tuieng
Ren Jie Tuieng
Numerade Educator
01:03

Problem 16

What is a record? What is a field?

Narayan Hari
Narayan Hari
Numerade Educator
02:46

Problem 17

Describe the way that you use a temporary file in a program that modifies a record in a sequential access file.

James Kiss
James Kiss
Numerade Educator
02:49

Problem 18

Describe the way that you use a temporary file in a program that deletes a record from a sequential file.

Joe Mallonee
Joe Mallonee
Numerade Educator
00:24

Problem 19

Briefly describe what an exception is.

James Kiss
James Kiss
Numerade Educator
01:01

Problem 20

If an exception is raised and the program does not handle it with a try/except statement, what happens?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
00:55

Problem 21

What type of exception does a program raise when it tries to open a nonexistent file?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:26

Problem 22

What type of exception does a program raise when it uses the float function to convert a non-numeric string to a number?

Florencia Cuzmar
Florencia Cuzmar
Numerade Educator