0% found this document useful (0 votes)
28 views2 pages

Text File Operations Worksheet for XII

The document contains a worksheet on working with text files in Python. It includes questions about reading and writing to text files, as well as manipulating the text using string and list methods. The questions cover opening, reading, writing, iterating over lines and splitting strings in text files.

Uploaded by

Mohamed Mufeed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Text File Operations Worksheet for XII

The document contains a worksheet on working with text files in Python. It includes questions about reading and writing to text files, as well as manipulating the text using string and list methods. The questions cover opening, reading, writing, iterating over lines and splitting strings in text files.

Uploaded by

Mohamed Mufeed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SHIFAN NOOR GLOBAL ACADEMY (CBSE)

Grade : XII Worksheet No - 1

Date:

Topic : Working with Text files

1) To read the next line of the file from a file object infi,we use

a) [Link](all) b) [Link]() c) [Link]() d) [Link]()

2)The readlines () method returns

a) str b)a list of lines c)a list of single characters d)a list of integers

3)To open a file c:\[Link] for appending data, we use

a)file = open(“c:\\[Link]”,”a”) b) file = open(“c:\\[Link]”,”rw”) c ) file = open(r)“c:\\[Link]”,”a”)

Predict the output:

1)Suppose the content of a text file [Link] is

“The way to get started is to quit talking and begin doing”

F = open(“[Link])

[Link](29)

S = [Link]()

Print(s)

2)Suppose the content of “[Link]” is:

a) “ A poem by paramahamsa yoganandha , ”

b) “India is looking for more investments around the globe”

What will be the output of the following code?

F = open(“[Link]”)
S = [Link]()
L = [Link]()
For i in L:
If len(i) % 3 !=0:
Print(i,end =”’)
3) What is the difference between read() and readlines() function?

4) Predict the output:


[Link]: “ Most Iconic Poems in the English Language ”
Fh = file(“[Link]”,”r”)

Line = [Link]()

Line = [Link]()

5)What happens if you try to open a file in ‘W’ mode that already exists?

6)What is the difference between a text file and binary file?

7) A text file contain alphanumeric text (say [Link]).Write a program that reads this text file and prints
only the numbers or digits from the file.

8)Read the code given below and answer the questions:

f=open(“[Link]”,”w”)

[Link](“Bye”)

[Link]()

If the file contains “good” before execution, what will be the contents of the file after execution of this
code?

9)What will be the output of the python code?

Rhymes,txt :

jack & jill

went up the hill

f =open(“[Link]”)
L= [Link]()
for i in L:
s = [Link]()
print(len(s),end=”#”)
a) 2#4# b)3#4# c)2# d)7#
10) Count the number of lines in a text file ‘[Link]’ which is starting with an alphabet ‘A’

Find the missing statement:

def countlines():
file = open(________________)
lines = file.__________()
count = 0
for w in lines:
if w[0] == “A” or w[0] == “a”
count = count __________
print(“Total lines started with ‘A’ or ‘a’” ,count)
file._______()

You might also like