Python File handling - Text file Quiz

Python File handling - Text file Quiz

Assessment

Quiz

Computers

12th Grade

Practice Problem

Hard

Created by

Sathasivan H

Used 16+ times

FREE Resource

Student preview

quiz-placeholder

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following command is used to open a file “c:\temp.txt” in read-mode only?

infile = open(“c:\temp.txt”, “r”)

infile = open(“c:\\temp.txt”, “r”)

infile = open(file = “c:\temp.txt”, “r+”)

infile = open(file = “c:\\temp.txt”, “r+”)

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following command is used to open a file “c:\temp.txt” in write-mode only?

outfile = open(“c:\temp.txt”, “w”)

outfile = open(“c:\\temp.txt”, “w”)

outfile = open(file = “c:\temp.txt”, “w+”)

outfile = open(file = “c:\\temp.txt”, “w+”)

3.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following command is used to open a file “c:\temp.txt” in append-mode?

outfile = open(“c:/temp.txt”, “a”)

outfile = open(“c:\temp.txt”, “w+”)

outfile = open(“c:\\temp.txt”, “a”)

outfile = open(“c:\\temp.txt”, “r+”)

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following statements are true regarding the opening modes of a file?

A. When you open a file for reading, if the file does not exist, an error occurs.

B. When you open a file for writing, if the file does not exist, an error occurs.

C. When you open a file for reading, if the file does not exist, the program will open an empty file.

D. When you open a file for writing, if the file does not exist, a new file is created.

E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

Only A

A and B

A, D and E

A, B and E

5.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?

file.read(n)

n = file.read()

file.readline(n)

file.readlines()

6.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?

tmpfile.read(n)

tmpfile.read()

tmpfile.readline()

tmpfile.readlines()

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?

tmpfile.read(n)

tmpfile.read()

tmpfile.readline()

tmpfile.readlines()

Create a free account and access millions of resources

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?