Python Reading files

Python Reading files

9th - 12th Grade

9 Qs

quiz-placeholder

Similar activities

Bitmap v Vector Images

Bitmap v Vector Images

KG - University

10 Qs

Text file Handling 1

Text file Handling 1

12th Grade

6 Qs

AP Computer Science Principles Unit 3 Review

AP Computer Science Principles Unit 3 Review

9th - 12th Grade

10 Qs

FILE HANDLING IN PYTHON

FILE HANDLING IN PYTHON

12th Grade

10 Qs

File Handling with Python

File Handling with Python

12th Grade - University

7 Qs

File Handling

File Handling

12th Grade

10 Qs

File Handling

File Handling

12th Grade

10 Qs

Computer Science Writing to a File

Computer Science Writing to a File

10th Grade

12 Qs

Python Reading files

Python Reading files

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Created by

Susan O'Connell

Used 55+ times

FREE Resource

9 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(song_file.read(4)) ?

I ca

I can

I c

I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(text_file.readline(8)) ?

I can't

I can

I can't write one song that's not about you

Error

3.

MULTIPLE SELECT QUESTION

1 min • 1 pt

Given a text file opened as file_in, which of the following will print the entire file? (Select ALL that apply.)

print(file_in.read())

print(file_in)

lines = file_in.readlines()

for line in lines:

print(line)

lines = file_in.readlines()

for i in range(len(lines)):

print(lines)

for line in file_in:

print(line)

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(text_file.readlines()[1]) ?

Can't drink without thinkin' about you

I can't write one song that's not about you

I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?

I

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to open the file file_in.txt for reading?

open('file_in.txt', 'r')

open('file_in.txt','r+')

open('file_in.txt','w')

open('file_in.txt','a')

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the best way to read an entire file into a single string?

.read()

.readline()

.readlines()

.read(all)

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the best way to read an entire file into a tuple?

.read()

.readline()

.readlines()

.read(all)

8.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the best way to read the first line of a file?

.read()

.readline()

.readlines()

.read(all)

9.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

When reading text files, what are the hidden characters typically at the end of each line?

\n

#

@

»