0% found this document useful (0 votes)
122 views

MCQ-Python FILE HANDLING-QB

MCQ python file

Uploaded by

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

MCQ-Python FILE HANDLING-QB

MCQ python file

Uploaded by

akuganesh29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

File Handling || Multiple Choice Questions || Class 12

(b) fobj.read()
1. To open a file c:\test.txt for reading, we should (c) fobj.readline()
give the statement: (d) fobj.readlines()

(a) filel = open("c:\ test.txt", "r")


(b) file1 = open("c:\\ test.txt", "r") 6. To read the entire contents of the file as a string
(c) file = open(file = "c:\ test.txt", "r") from a file object fobj, the command should be:
(d) file1 = open(file = "c:\\s test.txt", "r")
(a) fobj.read(2)
(b) fobj.read()
2. To open a file c:\ test.txt for writing, we should (c) fobj.readline()
use the statement: (d) fobj.readlines()

(a) fobj = open("c:\test.txt", "w")


(b) fobj = open("c:\\ test.txt", "w")
(c) fobj = open(file = "c:\ test.txt", "w") 7. What will be the output of the following
(d) fobj = open(file = "c:\\ test.txt", "w") snippet?

f = None
3. To open a file c:\ test.txt for appending data, we for i in range (5):
can give the statement: with open ("data.txt", "W") as f:

(a) fobj = open("c:\\ test.txt", "a") if i > 2:


(b) fobj = open("c:\\ test.txt", "rw") break
(c) fobj = open(file = "c:\test.txt", "w") print (f.closed)
(d) fobj = open(file = "c:\\ test.txt", "w")
(a) True
(b) False
4. Which of the following statements is/are true? (c) None
(d) Error
(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 8. To read the next line of the file from a file object
not exist, a new file is created. fobj, we use:
(c) When you open a file for writing, if the file
exists, the existing file is overwritten with the new (a) fobj.read(2)
file. (b) fobj.read()
(d) All of the above. (c) fobj.readline()
(d) fobj.readlines()

5. To read two characters from a file object from,


the command should be: 9. To read the remaining lines of the file from a file
1

object fobj, we use:


Page

(a) fobj.read(2)
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
(a) fobj.read(2) (c) fobj.writelines(sequence)
(b) fobj.read() (d) fobj.writeline()
(c) fobj.readline()
(d) fobj.readlines
15. In file handling, what do the terms "r" and "a"
stand for?
10. The readlines() method returns:
(a) read, append
(a) String (b) append, read
(b) A list of integers (iii) write, append
(c) A list of single characters (d) None of the above
(d) A list of lines

16. Which of the following is not a valid mode to


11. Which module is required to use the built-in open a file?
function dump( )?
(a) ab
(a) math (b) rw
(b) flush (c) r+
(c) pickle (d) w+
(d) unpickle

17. Which statement is used to change the file


12. Which of the following functions is used to position to an offset value from the start?
write data in the binary mode?
(a) fp.seek(offset, 0)
(a) write (b) fp.seek(offset, 1)
(b) output (c) fp.seek(offset, 2)
(c) dump (d) None of the above
(d) send

18. The difference between r+ and w+ modes is


13. Which is/are the basic I/O (input-output) expressed as?
stream(s) in file?
(a) No difference
(a) Standard Input (b) In r+ mode, the pointer is initially placed at the
(b) Standard Output beginning of the file and the pointer is at the end
(c) Standard Errors for w+
(d) All of the above (c) In w+ mode, the pointer is initially placed at the
beginning of the file and the pointer is at the end
for r+
14. Which of the following is the correct syntax of (d) Depends on the operating system
file.writelines()?
2

(a) file.writelines(sequence) 19. What does CSV stand for?


Page

(b) fobj.writelines()
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
(a) Cursor Separated Variables (c) +
(b) Comma Separated Values (d) b
(c) Cursor Separated Values
(d) Cursor Separated Version
25. Every record in a CSV file is stored in reader
object in the form of a list using which method?
20. Which module is used for working with CSV
files in Python? (a) writer()
(b) append()
(a) random (c) reader()
(b) statistics (d) list()
(c) csv
(d) math
26. Information stored on a storage device with a
specific name is called a _____.
21. Which of the following modes is used for both
writing and reading from a binary file? (a) array
(b) dictionary
(a) wb+ (c) file
(b) w (d) tuple
(c) wb
(d) w+
27. Which of the following format of files can be
created programmatically through Python to some
22. Which statement is used to retrieve the data?
current position within the file?
(a) Data files
(a) fp.seek() (b) Text files
(b) fp.tell() (c) Video files
(c) fp.loc (d) Binary files
(d) fp.pos

28. To open a file c:\ss.txt for appending data, we


23. What happens if no arguments are passed to use
the seek() method?
(a) file = open("c:\\ss.txt", "a")
(a) file position is set to the start of file (b) file = open("c:\\ss.txt", "rw")
(b) file position is set to the end of file (c) file = open(r"c\ss.txt", "a")
(c) file position remains unchanged (d) file = open(file = "c:\ss.txt", "w")
(d) results in an error (e) file = open(file = "c\\ss.txt", "w")
(f) file = open("c\ res.txt")

24. Which of the following modes will refer to


binary data? 29. To read the next line of the file from a file
3

(a) r object infi, we use


Page

(b) w
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
(a) infi.read(all) (c) readall()
(b) infi.read() (d) readchar()
(c) infi.readline()
(d) infi.readlines()
35. Which function is used to read single line from
file?
30. To read the remaining lines of the file from a
file object infi, we use (a) readline()
(b) readlines()
(a) infi.read(all) (c) readstatement( )
(b) infi.read() (d) readfulline()
(c) infi.readline()
(d) infi.readlines()
36. Which function is used to write all the
characters?
31. The readlines() method returns
(a) write()
(a) str (b) writecharacters()
(b) a list of lines (c) writeall()
(c) a list of single characters (d) writechar()
(d) a list of integers

37. Which function is used to write a list of strings


32. Which of the following mode will refer to in a file?
binary data?
(a) writeline()
(a) r (b) writelines()
(b) w (c) writestatement()
(c) + (d) writefullline()
(d) b

38. Which of the following is modes of both writing


33. In file handling, what does this term means "r, and reading in binary format in file?
a"?
(a) wb+
(a) read, append (b) w
(b) append, read (c) wb
(c) all of the mentioned (d) w+
(d) none of these

39. Which of the following is not a valid mode to


34. Which function is used to read all the open a file?
characters?
(a) ab
4

(a) read() (b) rw


Page

(b) read characters() (c) r+


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
(d) w+ 28. a, c
29. c
30. d
40. What is the difference between r+ and w+ 31. b
modes? 32. d
33. a
(a) No difference. 34. a
(b) In r+ mode, the pointer is initially placed at the 35. a
beginning of the file and for w+, the pointer is 36. a
placed at the end. 37. b
(c) In w+ mode, the pointer is initially placed at the 38. a
beginning of the file and for r+, the pointer is 39. b
placed at the end. 40. b
(d) Depends on the operating system.
File Handling || Fill in the Blanks || Class 12

Answers:

1. b 1. _____ in Python are interpreted as a sequence


2. b or stream of bytes stored on some storage media.
3. a
4. d
5. a 2. The _____ function creates a file object used to
6. b call other support methods associated with it.
7. a
8. c 3. Files in Python can be opened in one of the
9. d three modes - _____, _____ and _____.
10. d
11. c
4. The _____ method writes a list of strings to a
12. c
13. d file.
14. c
15. a 5. The _____ method of a file object flushes any
16. b unwritten information and closes the file object.
17. a
18. b
6. The name of the current working directory can
19. b
be determined using _____ method.
20. c
21. a
22. b 7. The_____ method is used to rename the file or
23. d folder.
24. d
25. c 8. The _____ method is used to remove/delete a
5

26. c
Page

file.
27. b, d
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
9. A _____ file is a series of 1's and 0's, treated as 22. _____ object contains the number of the
raw data and read byte-by-byte. current line in a CSV file.

10. The _____ statement automatically closes the 23. To end all the file contents in the form of a list,
file after the processing on the file gets over. _____ method may be used.

11. The read() function reads data from the _____ 24. To read all the file contents, _____ method is
of a file. used.

12. The pickle module produces two main methods 25. To force Python to write the contents of file
called _____ and ____ for writing and reading buffer on to storage file, _____ method may be
operations. used.

13. The readlines() returns a list of lines from the 26. The default file-open mode is _____ mode.
file till _____.
27. A _____ governs the type of operations (e.g.,
14. The _____ method reads 'n' characters from read/write/append) possible in the opened file.
the file.
28. The two types of data files can be _____ files
15. _____ function is used to force transfer of data and _____ files.
from buffer to file.
29. The other name for file object is _____.
16. _____ format is a text format accessible to all
applications across several platforms. 30. The _____ file mode will open a file for read
and write purpose.
17. _____ method is used for random access of
data in a CSV file. 31. The _____ file mode will open a file for write
and read purpose.
18. _____ method of pickle module is used to
write an object into binary file. 32. To close an open file, _____ method is used.

19. _____ method of pickle module is used to read 33. To read all the file contents in form of a list,
data from a binary file. ______ method is used.

20. _____ statement is given for importing csv 34. To write a list in a file, _____ method may be
module into your program. used.
6

21. _____ is a string method that joins all values of 35. To force Python to write the contents of file
Page

each row with comma separator in CSV. buffer on to storage file, _____ method may be
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
used. File Handling || True or False || Class 12

Answers:

1. Files
1. An absolute path always begins with the root
2. open()
3. read ('r'), write ('w'), append ('a') folder.
4. writelines()
5. close() 2. It is not necessary to always create the file in the
6. getcwd() same default folder where Python has been
7. rename() installed.
8. remove()
9. binary
3. In binary file, there is no delimiter for a line.
10. with
11. (beginning)
12. dump(), load() 4. A binary file stores information in ASCII or
13. end of file (EOF) Unicode characters.
14. read(n)
15. flush() 5. readline() reads the entire file at a time.
16. CSV
17. seek()
6. A close() function breaks the link of the file
18. dump()
19. load() object and the file on the disk.
20. import csv
21. join() 7. When you open a file in read mode, the given
22. line_num file must exist in the folder, otherwise Python will
23. readlines() raise FileNotFound error.
24. writelines()
25. flush()
8. The default file open mode is write mode.
26. read
27. file mode
28. text, binary 9. Opening a file in append mode erases the
29. file handle previous data.
30. r+
31. w+ or a+ 10. A file mode defines the type of operations that
32. close()
is to be performed on the file.
33. readlines()
7

34. writelines()
Page

35. flush() 11. A stream is defined as a sequence of

S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..


characters. 22. Comma is the default delimiter for a CSV file.

12. readlines() function returns a list of strings, 23. tell() method of Python tells us the current
each separated by "\n". position within the file.

13. file() and open() functions have different 24. The offset argument to seek() method
usage. indicates the number of bytes to be moved.

14. Data maintained inside the file is termed as 25. If the offset value is set to 2, beginning of the
"persistent” (permanent in nature) data. file would be taken as seek position.

15. with statement ensures that all the resources 26. When you open a file for reading, if the file
allocated to the file objects get deallocated does not exist, an error occurs.
automatically.
27. When you open a file for writing, if the file
16. CSV module can handle CSV files correctly does not exist, an error occurs.
regardless of the operating system on which the
files were created. 28. When you open a file for writing, if the file
exists, the existing file is overwritten with the new
17. CSV module gets automatically imported into file.
your program for reading a CSV file.
29. The absolute paths are from the topmost level
18. The type of operation that can be performed of the directory structure.
on a file depends upon the file mode in which it is
opened. 30. The relative paths are relative to current
working directory.
19. Functions readline() and readlines() are
essentially the same. 31. The relative path for a file always remains
same even after changing the directory.
20. Every record in a CSV file is stored in reader
object in the form of a list. 32. The types of operations that can be carried out
on a file depends upon the file mode a file is
21. writerow() method allows us to write a list of opened in.
fields to the CSV file.
8
Page

33. If no path is given with a file name in the file


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
open(), then the file must exist in current 23. True
directory. 24. True
25. False
34. Functions readline() and readlines() are 26. True
essentially the same. 27. False
28. True
35. Python automatically flushes the file buffers 29. True
before closing a file with close() function. 30. True
31. False
32. True
33. True
Answers: 34. False
35. True
1. True
File Handling || Important Questions || Class 12
2. False || Sumita-Arora || Preeti-Arora || Computer
3. True Science
4. False
5. False
6. True
7. True
Q. What are the different file-processing modes
8. False supported by Python?
9. False
10. True
11. False
Q. What is the difference between readline() and
12. True readlines() function?
13. False
14. True
15. True Q. What is the difference between "w" and "a"
16. True modes?
17. False
18. True
19. False Q. Differentiate between file modes r+ and w+
20. True with respect to python.

21. True
9
Page

22. True
S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
Q. Differentiate between file modes r+ and rb+
with respect to Python.

Q. Write a function file_long() that accepts a


filename and reports the file's longest line.

Q. What would be the data type of variable data in


the following statements?
Q. Write a program to count the number of
(a) data = f.read() uppercase alphabets present in a text file
(b) data = f.read(10) "Pome.txt".
(c) data = f.readline()
(d) data = f.readlines()

Q. Write a function remove_lowercase() that


accepts two file names, and copies all lines that do
Q. What are the advantages of saving data in: not start with a lowercase letter from the first file
to the second file.
(i) Binary form
(ii) Text form

Q. Write a program that reads characters from the


keyboard one by one. All lower case characters get
Q. What is a CSV file? stored inside the file LOWER, all upper case
characters get stored inside the file UPPER and all
other characters get stored inside file OTHERS.

Q. What are the advantages of CSV file formats?

Q. Reading a file line by line from the beginning


What if you want to read a file backward? This
Q. Differentiate between a text file and a binary happens when you need to read log files. Write a
file. program to read and display content of file from
end to beginning.

Q. Write a method in Python to read lines from a


text file MYNOTES.TXT and display those lines Q. Write a statement in Python to perform the
which start with the alphabet 'K'. following operations:

• To open a text file "MYPET.TXT" in write mode


• To open a text file "MYPET.TXT" in read mode
Q. What are the advantages of saving data in:
10

(i) Binary form


Page

(ii) Text form Q. Write a method in Python to write multiple


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
lines of text contents into a text file daynote.txt
line.

Q. Write a method in Python to read lines from a


text file DIARY.TXT and display those lines which
Q. Write a Python program to display the size of a start with the alphabet 'P'.
file after removing EOL characters, leading and
trailing white spaces and blank lines.

Q. Consider the file “SarojiniPoem.txt”


Q. Write a user-defined function in Python that
displays the number of lines starting with 'H' in the Autumn Song
file Para.
Like a joy on the heart of a sorrow,
txt. Example, if the file contains: The sunset hangs on a cloud;
Whose woods these are I think I know. A golden storm of glittering sheaves,
His house is in the village though; Of fair and frail and fluttering leaves,
He will not see me stopping here The wild wind blows in a cloud.
To watch his woods fill up with snow.
Then the line count should be 2. Hark to a voice that is calling
To my heart in the voice of the wind:
My heart is weary and sad and alone,
For its dreams like the fluttering leaves have gone,
Q. Consider a binary file Employee.dat containing And why should I stay behind?
details such as empno: ename: salary (separator
':'). Write a Python function to display details of Sarojini Naidu
those employees who are earning between 20000
and 40000 (both values inclusive).
Based on the above file, answer the following
question:

Q. Write a function countmy() in Python to read (a) What would be the output of following code?
the text file "DATA.TXT" and count the number of
times "my" occurs in the file. file = open ("sarojiniPoem.txt","r")
For example, if the file "DATA.TXT" contains "This text = file.readlines()
is my website. I have displayed my preferences in file.close()
the CHOICE section." - the countmy() function for line in text :
should display the output as: "my occurs 2 times". print (line , end = ' ' )
print ( )

(b) Modify the program so that the lines are


Q. Write a method/function DISPLAYWORDS() in printed in reverse order.
11

python to read lines from a text file STORY.TXT,


and display those words, which are less than 4 (c) Modify the code so as to output to another file
Page

characters. instead of the screen. Let your script overwrite the


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
output file.

(d)Change the script of part (c) that it append


output to an existing file. Q. Create a file phonebook.det that stores the
details in following format:
(e) Modify the program so that each line is printed
with a line number at beginning. Name Phone
Jiving 8666000
Kriti 1010101
:

Q. Write a program using Dictionary and Text files Obtain the details from the user.
to store roman numbers and find their
equivalents.

Q. Write a program to edit the phone number of


“Arvind” infile “phonebook.det”. If there is no
Q. Observe the following code and answer the record for “Arvind”, report error.
questions that follow:

File = open ("Mydata","a")


_______#Blank1 Q. Write a function in Python to count the number
File.close() of lines in a text file 'STORY.TXT' which are starting
with the alphabet 'A'.
(i) What type (Text/Binary) of file is Mydata?
(ii) Fill the Blank1 with statement to write "ABC" in
the file "Mydata"
Q. A text file contains alphanumeric text (say
an.txt). Write a program that reads this text file
and prints only the numbers or digits from the file.
Q. How many file objects would you need to
manage the following situations:

(a) To process four files sequentially. Q. Write a function in python to count the number
(b) To merge two sorted files into third file. of lines in a text file 'STORY.TXT' which is starting
with an alphabet 'A'.

Q. Write a program that reads a text file and then


create a new file where each character‘s case is Q. Following is the structure of each record in a
inverted. data file named "PRODUCT.DAT".

("prod_code": value, "prod_desc": value, "stock":


12

value)
Q. Write code to print just the last line of a text file
Page

'data.txt'. The values for prod_code and prod_desc are


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
strings and the value for stock is an integer. Q. Differentiate between file modes r+ and w+

Write a function in Python to update the file with a with respect to python.
new value of stock. The stock and the
product_code, whose stock is to be updated, are
to be inputted during the execution of the
function.
Q. Differentiate between file modes r+ and rb+
with respect to Python.

Q. Create a CSV file "Groceries" to store


information of different items existing in a shop.
The information is to be stored w.r.t. each item
code, name, price, qty. Write a program to accept
the data from user and store it permanently in CSV
file. Q. What would be the data type of variable data in
the following statements?
File Handling || Important Questions || Class 12
|| Sumita-Arora || Preeti-Arora || Computer (a) data = f.read()
Science (b) data = f.read(10)
(c) data = f.readline()
(d) data = f.readlines()

Q. What are the different file-processing modes


supported by Python? Q. What are the advantages of saving data in:

(i) Binary form


(ii) Text form
Q. What is the difference between readline() and
readlines() function?

Q. What is a CSV file?

Q. What is the difference between "w" and "a"


modes?
Q. What are the advantages of CSV file formats?
13
Page

S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..


Q. Differentiate between a text file and a binary
file. Q. Write a program that reads characters from the
keyboard one by one. All lower case characters get
stored inside the file LOWER, all upper case
characters get stored inside the file UPPER and all
Q. Write a method in Python to read lines from a other characters get stored inside file OTHERS.
text file MYNOTES.TXT and display those lines
which start with the alphabet 'K'.

Q. Reading a file line by line from the beginning


What if you want to read a file backward? This
Q. What are the advantages of saving data in: happens when you need to read log files. Write a
program to read and display content of file from
(i) Binary form end to beginning.
(ii) Text form

Q. Write a statement in Python to perform the


Q. Write a function file_long() that accepts a following operations:
filename and reports the file's longest line.
• To open a text file "MYPET.TXT" in write mode
• To open a text file "MYPET.TXT" in read mode

Q. Write a program to count the number of


uppercase alphabets present in a text file
"Pome.txt". Q. Write a method in Python to write multiple
lines of text contents into a text file daynote.txt
line.

Q. Write a function remove_lowercase() that


accepts two file names, and copies all lines that do
not start with a lowercase letter from the first file Q. Write a Python program to display the size of a
14

to the second file. file after removing EOL characters, leading and
Page

trailing white spaces and blank lines.


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
python to read lines from a text file STORY.TXT,
and display those words, which are less than 4
characters.
Q. Write a user-defined function in Python that
displays the number of lines starting with 'H' in the
file Para.
Q. Write a method in Python to read lines from a
txt. Example, if the file contains: text file DIARY.TXT and display those lines which
Whose woods these are I think I know. start with the alphabet 'P'.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.
Then the line count should be 2.
Q. Consider the file “SarojiniPoem.txt”

Autumn Song
Q. Consider a binary file Employee.dat containing
details such as empno: ename: salary (separator Like a joy on the heart of a sorrow,
':'). Write a Python function to display details of The sunset hangs on a cloud;
those employees who are earning between 20000 A golden storm of glittering sheaves,
and 40000 (both values inclusive). Of fair and frail and fluttering leaves,
The wild wind blows in a cloud.

Hark to a voice that is calling


Q. Write a function countmy() in Python to read To my heart in the voice of the wind:
the text file "DATA.TXT" and count the number of My heart is weary and sad and alone,
times "my" occurs in the file. For its dreams like the fluttering leaves have gone,
For example, if the file "DATA.TXT" contains "This And why should I stay behind?
is my website. I have displayed my preferences in
the CHOICE section." - the countmy() function Sarojini Naidu
should display the output as: "my occurs 2 times".

Based on the above file, answer the following


15

question:
Page

Q. Write a method/function DISPLAYWORDS() in


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
(a) What would be the output of following code? _______#Blank1
File.close()
file = open ("sarojiniPoem.txt","r")
text = file.readlines() (i) What type (Text/Binary) of file is Mydata?
file.close() (ii) Fill the Blank1 with statement to write "ABC" in
for line in text : the file "Mydata"
print (line , end = ' ' )
print ( )

(b) Modify the program so that the lines are Q. How many file objects would you need to
printed in reverse order. manage the following situations:

(c) Modify the code so as to output to another file (a) To process four files sequentially.
instead of the screen. Let your script overwrite the (b) To merge two sorted files into third file.
output file.

(d)Change the script of part (c) that it append


output to an existing file. Q. Write a program that reads a text file and then
create a new file where each character‘s case is
(e) Modify the program so that each line is printed inverted.
with a line number at beginning.

Q. Write code to print just the last line of a text file


'data.txt'.
Q. Write a program using Dictionary and Text files
to store roman numbers and find their
equivalents.
Q. Create a file phonebook.det that stores the
details in following format:

Q. Observe the following code and answer the Name Phone


questions that follow: Jiving 8666000
16

Kriti 1010101
Page

File = open ("Mydata","a") :


S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..
The values for prod_code and prod_desc are
Obtain the details from the user. strings and the value for stock is an integer.

Write a function in Python to update the file with a


new value of stock. The stock and the
Q. Write a program to edit the phone number of product_code, whose stock is to be updated, are
“Arvind” infile “phonebook.det”. If there is no to be inputted during the execution of the
record for “Arvind”, report error. function.

Q. Write a function in Python to count the number Q. Create a CSV file "Groceries" to store
of lines in a text file 'STORY.TXT' which are starting information of different items existing in a shop.
with the alphabet 'A'. The information is to be stored w.r.t. each item
code, name, price, qty. Write a program to accept
the data from user and store it permanently in CSV
file.
Q. A text file contains alphanumeric text (say
an.txt). Write a program that reads this text file
and prints only the numbers or digits from the file.

Q. Write a function in python to count the number


of lines in a text file 'STORY.TXT' which is starting
with an alphabet 'A'.

Q. Following is the structure of each record in a


data file named "PRODUCT.DAT".

("prod_code": value, "prod_desc": value, "stock":


17

value)
Page

S SHUNMUGA SUNDARAM , M.E/CS, A.M.I.E, MISTE, IAENG..

You might also like