Tuesday, July 24, 2018

Python Data Structures - Chapter 7 Quiz

Chapter 7 Quiz

Quiz, 10 questions
Question 1
1
point

1. Question 1

Given the architecture and terminology we introduced in Chapter 1, where are files stored?
Question 2
1
point

2. Question 2

What is stored in a "file handle" that is returned from a successful open() call?
Question 3
1
point

3. Question 3

What do we use the second parameter of the open() call to indicate?
Question 4
1
point

4. Question 4

What Python function would you use if you wanted to prompt the user for a file name to open?
Question 5
1
point

5. Question 5

What is the purpose of the newline character in text files?
Question 6
1
point

6. Question 6

If we open a file as follows:
1
xfile = open('mbox.txt')
What statement would we use to read the file one line at a time?
Question 7
1
point

7. Question 7

What is the purpose of the following Python code?
1
2
3
4
5
fhand = open('mbox.txt')
x = 0
for line in fhand:
x = x + 1
print(x)
Question 8
1
point

8. Question 8

If you write a Python program to read a text file and you see extra blank lines in the output that are not present in the file input as shown below, what Python string function will likely solve the problem?
1
2
3
4
5
6
7
8
9
From: stephen.marquard@uct.ac.za
From: louis@media.berkeley.edu
From: zqian@umich.edu
From: rjlowe@iupui.edu
...
Question 9
1
point

9. Question 9

The following code sequence fails with a traceback when the user enters a file that does not exist. How would you avoid the traceback and make it so you could print out your own error message when a bad file name was entered?
1
2
fname = input('Enter the file name: ')
fhand = open(fname)
Question 10
1
point

10. Question 10

What does the following Python code do?
1
2
fhand = open('mbox-short.txt')
inp = fhand.read()

No comments:

Post a Comment