File Handling in Python -Revision test
Quiz
•
Computers
•
12th Grade
•
Practice Problem
•
Hard
Naresh K Rana
Used 4+ times
FREE Resource
Enhance your content in a minute
30 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A text file story.txt contains 500 lines. Which method is MOST memory-efficient for counting the number of lines?
len(f.readlines())
f.read().count("\n")
Iterating with for line in f and counting
f.readline() repeatedly storing in a list
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A text file contains: Hello Python 123 Code What will f.read().split() return?
['Hello', 'Python', '123', 'Code']
['Hello Python', '123 Code']
['Hello Python\n123 Code']
['Hello', 'Python\n123', 'Code']
3.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which statement is TRUE about file reading in Python?
read() reads line by line
readline() reads the whole file
readlines() reads entire file into a list
read() returns list of strings
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
If a text file pointer is at the end after reading, which function resets it to the beginning?
f.restart()
f.flush()
f.seek(0)
f.reset()
5.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Consider: f=open("data.txt","r") print(f.readline(4)) If file contains "Python", output will be:
"Python"
"Pyth"
"Py"
Error
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
To count the number of words in a text file, the best approach is:
Count spaces
Use .split() on each line
Use .count(" ")
Count characters
7.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A file is opened in "r+" mode. Which is TRUE?
Can read but not write
Can write but not read
Can read and write both
Only creates a new file
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
25 questions
[ SMP-VII ] PTS II
Quiz
•
12th Grade - University
25 questions
Jaringan Komputer
Quiz
•
9th - 12th Grade
25 questions
Arduino2 - display
Quiz
•
9th - 12th Grade
25 questions
ICT ebanyvrot
Quiz
•
12th Grade - University
25 questions
Simple Machines
Quiz
•
KG - University
25 questions
Susulan Computer Networking Quiz
Quiz
•
12th Grade
25 questions
Pemahaman Materi Dampak Sosial Informatika
Quiz
•
12th Grade
25 questions
Computer Application TQ1
Quiz
•
1st Grade - University
Popular Resources on Wayground
8 questions
2 Step Word Problems
Quiz
•
KG - University
20 questions
Comparing Fractions
Quiz
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Latin Bases claus(clois,clos, clud, clus) and ped
Quiz
•
6th - 8th Grade
22 questions
fractions
Quiz
•
3rd Grade
7 questions
The Story of Books
Quiz
•
6th - 8th Grade
Discover more resources for Computers
8 questions
2 Step Word Problems
Quiz
•
KG - University
10 questions
Martin Luther King, Jr. For Kids
Interactive video
•
1st - 12th Grade
10 questions
Dr. King's Speech and Its Impact
Interactive video
•
7th - 12th Grade
20 questions
-AR -ER -IR present tense
Quiz
•
10th - 12th Grade
7 questions
Anti-Bullying ARS 15-341
Quiz
•
9th - 12th Grade
13 questions
Model Exponential Growth and Decay Scenarios
Quiz
•
9th - 12th Grade
15 questions
TSI Math Practice Questions
Quiz
•
8th - 12th Grade
24 questions
Identify Properties of Polygons and Quadrilaterals
Quiz
•
9th - 12th Grade
