

Text file handling (reading name and mark from a file)
Presentation
•
Computers
•
11th Grade
•
Practice Problem
•
Medium
Kenneth Tai
Used 3+ times
FREE Resource
2 Slides • 5 Questions
1
Multiple Choice
Which instruction is used to create a text file for storing the data?
open(file1,"r")
open(file1,"w")
file1=open("file.txt","r")
file1=open("file.txt","a")
2
Multiple Choice
Which instructions can write three text data into a text file in three separated lines?
for i in range(3):
file1.write(data)
for i in range(3):
write(data+"\n")
for i in range(3):
file1.write(data+"\n")
for i in range(3):
file1.writelines(data+"\n")
3
Multiple Choice
Which instruction can read out all data from a text file and store the data in a list?
data=file1.read()
data = file1.readlines()
data = file1.readline()
data = file1.readlist()
4
Multiple Choice
Which instruction can remove "\n" from data?
data=data.strip()
data.strip()=data
data=strip().data
data=strip(data)
5
Multiple Choice
item=["Peter 50", "Paul 48", "Mary 45"]
Which instructions can use to split the data in items and store the name and the number separately?
data=item[1].split()
name=data[0]
age=data[1]
data=item.split()
name=data[0]
age=data[1]
data=split(item)
name=data[0]
age=data[1]
name=data.split()
age=data.split()
6
Reading out name and mark from a text file
file1=open("name_mark.txt","r")
outputstring=file1.readlines()
print(outputstring)
name=[""]*len(outputstring) #initialize the name array with size outputstring
mark=[0]*len(outputstring) #initialize the mark array with size outputstring
for i in range(len(outputstring)):
outputstring[i]=outputstring[i].strip()
item=outputstring[i].split() #split the outputstring into a list item
print(item)
name[i]=item[0] #store first item as name
mark[i]=int(item[1]) #store second item as mark
file1.close
for i in range(len(outputstring)):
print(name[i],mark[i])
7
Algorithm:
•a=[7,4,6,8,1,5]
for i = 0 to len(a) - 2
for j = 0 to (len(a) – i - 2)
if a [j] > a[j + 1]
swap the items
endif
next j
next i
Which instruction is used to create a text file for storing the data?
open(file1,"r")
open(file1,"w")
file1=open("file.txt","r")
file1=open("file.txt","a")
Show answer
Auto Play
Slide 1 / 7
MULTIPLE CHOICE
Similar Resources on Wayground
11 questions
intro to AI 2
Presentation
•
10th - 11th Grade
9 questions
Struktur Artikel
Presentation
•
12th Grade
7 questions
Tugas GTA 8 - Lesson Presentation
Presentation
•
KG
5 questions
Review Daily Test
Presentation
•
11th Grade
6 questions
TEKS EDITORIAL
Presentation
•
12th Grade
10 questions
AP Chem Unit 01 Most Challenging Questions
Presentation
•
11th Grade
8 questions
Ukuran Tata Letak data tunggal
Presentation
•
10th Grade
8 questions
ID 10 Unit 1 lesson
Presentation
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade