Py4e: Chapter 7- Questions and Answers
|Latest Update
What Python function would you use if you wanted to prompt the user for a file name to
open? Correct Ans-input( )
What is the purpose of the newline character in text files? Correct Ans-It indicates the end of
one line of text and the beginning of another line of text
If we open a file as follows:
xfile = open('mbox.txt') Correct Ans-for line in xfile:
What is the purpose of the following Python code?
fhand = open('mbox.txt')
x=0
for line in fhand:
x=x+1
print(x) Correct Ans-Count the lines in the file '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:
|Latest Update
What Python function would you use if you wanted to prompt the user for a file name to
open? Correct Ans-input( )
What is the purpose of the newline character in text files? Correct Ans-It indicates the end of
one line of text and the beginning of another line of text
If we open a file as follows:
xfile = open('mbox.txt') Correct Ans-for line in xfile:
What is the purpose of the following Python code?
fhand = open('mbox.txt')
x=0
for line in fhand:
x=x+1
print(x) Correct Ans-Count the lines in the file '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: