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

Unit 4_python Programming _question Bank_2023-24

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)
42 views

Unit 4_python Programming _question Bank_2023-24

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/ 2

ABES ENGINEERING COLLEGE, GHAZIABAD

Unit-4
QUESTION BANK
SUBJECT NAME: PYTHON PROGRAMMING
SUBJECT CODE: BCC-302

Q.No Description CO BL
What are the primary modes in which you can open a file in Python
1 CO4 K2
for reading and writing? Explain each mode briefly.
Explain the difference between text mode ('t') and binary mode ('b')
2 CO4 K2
when opening a file in Python.
What is the purpose of the with statement when working with files in
3 CO4 K2
Python? Provide an example.
What is the purpose of the with statement when working with files in
4 CO4 K2
Python? Provide an example.
What are the common methods for reading a file in Python, and when
5 CO4 K2
would you use each of them (e.g., read(), readline(), readlines())?
How can you iterate through a file line by line in Python without
6 CO4 K2
reading the entire file into memory?
Explain the concept of a file pointer in Python. How can you
manipulate it using the seek() method? When working with files,
7 CO4 K2
what is the difference between the tell() and seek() methods in
Python?
Explain the use of the writelines() method. When would you prefer
8 CO4 K2
it over the write() method for writing data to a file?
Write Python code to read the contents of a text file named "sample.txt"
9 CO4 K3
and print its contents to the console.
Write a Python program to copy the contents of one text file to another text
10 CO4 K3
file.
Create a function that reads a text file and counts the number of words
11 CO4 K3
in it. Test the function with a sample file.
Write a Python program to append a line of text to an existing file
12 CO4 K3
named "output.txt."
Write a function in Python to count and display the total number of
13 CO4 K3
words in a text file
Write a function in Python to read lines from a text file "notes.txt".
14 Your function should find and display the occurrence of the word CO4 K3
"the"
Write a function display_words() in python to read lines from a text
15 file "story.txt", and display those words, which are less than 4 CO4 K3
characters.
16 How to open and close file? Also give the Syntax for same. CO4 K2
17 Differentiate between file modes r+ and w+ with respect to Python. CO4 K2
18 List down the steps involved in processing a large file in Python? CO4 K2
ABES ENGINEERING COLLEGE, GHAZIABAD

When trying to open a file in Python, I get the error CO4 K2


19 “FileNotFoundError: [Errno 2] No such file or directory”. What
could be the cause of this issue?
CO4 K2
20 Which functions allow us to check if we have reached the end of a
file in Python?

You might also like