This course will introduce the core data structure of the Python programming ... And, the answer is only for hint . it is helpful for those student who haven't submit Assignment and who confused ... These five lines are the lines to do this particular assignment where we are ...
chapter 7 week 3 quiz
Get link
Facebook
X
Pinterest
Email
Other Apps
chapter 7 week 3 quiz
chapter 7 week 3 quiz
Quiz
Given the architecture and terminology we introduced in Chapter 1, where are files stored?
Main Memory
Central Processor
Motherboard
Secondary memory
What is stored in a "file handle" that is returned from a successful open() call?
The handle contains the first 10 lines of a file
The handle has a list of all of the files in a particular folder on the hard drive
All the data from the file is read into memory and stored in the handle
The handle is a connection to the file's data
What do we use the second parameter of the open() call to indicate?
Whether we want to read data from the file or write data to the file
How large we expect the file to be
The list of folders to be searched to find the file we want to open
What disk drive the file is stored on
What Python function would you use if you wanted to prompt the user for a file name to open?
read()
file_input()
cin
input()
What is the purpose of the newline character in text files?
It allows us to open more than one files and read them in a synchronized manner
It enables random movement throughout the file
It indicates the end of one line of text and the beginning of another line of text
It adds a new network connection to retrieve files from the network
If we open a file as follows: xfile = open('mbox.txt')
What statement would we use to read the file one line at a time?
while() {
for line in xfile:
while((line = xfile.readLinr()) != null ) {
READ xfile INTO LINE
What is the purpose of the following Python code? fhand = open('mbox.txt')
x = 0
for line in fhand:
x = x + 1
print(x)
Convert the lines in mbox.txt to lower case
Count the lines in the file 'mbox.txt'
Reverse the order of the lines in mbox.txt
Remove the leading and trailing spaces from each line in mbox.txt
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? From: stephen.marquard@uct.ac.za
From: louis@media.berkeley.edu
From: zqian@umich.edu
From: rjlowe@iupui.edu
...
ljust()
rstrip()
trim()
startswith()
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?
fname = input('Enter the file name: ')
fhand = open(fname)
signal handlers
setjmp / longjmp
try / except
try / catch / finally
What does the following Python code do? fhand = open('mbox-short.txt')
inp = fhand.read()
Prompts the user for a file name
Checks to see if the file exists and can be written
Reads the entire file into the variable inp as a string
Turns the text in the file into a graphic image like a PNG or JPG
9.4 Write a program to read through the mbox-short.txt and figure out who has sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file. After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer. Answer:
10.2 Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages. You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon. From stephen.marquard@uct.ac.za Sat Jan 5 09 :14:16 2008 Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below. Answer:
6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out. Answer:
Very nice
ReplyDelete