0% found this document useful (0 votes)
1 views1 page

Python Questions

The document is a Python programming question paper focused on file handling, consisting of 10 questions divided into three sections. Section A covers basic file operations, Section B addresses file processing and analysis, and Section C explores advanced file handling techniques. Each question requires writing Python programs that utilize appropriate file handling modes and exception handling.

Uploaded by

tomjerry262003
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)
1 views1 page

Python Questions

The document is a Python programming question paper focused on file handling, consisting of 10 questions divided into three sections. Section A covers basic file operations, Section B addresses file processing and analysis, and Section C explores advanced file handling techniques. Each question requires writing Python programs that utilize appropriate file handling modes and exception handling.

Uploaded by

tomjerry262003
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
You are on page 1/ 1

Python Question Paper

Subject: Python Programming

Topic: File Handling

Total Questions: 10

Instructions:
- Write Python programs to solve the following problems.
- Use appropriate file handling modes and exception handling where necessary.

Section A: Basic File Operations (Q1 - Q3)


Q1. Write a Python program to create a text file named `sample.txt`, write your name and a
message into it, and then close the file.

Q2. Write a program to read and display the contents of `sample.txt`.

Q3. Write a Python script to append a new line `"This is an appended line"` to `sample.txt`
and display the updated content.

Section B: File Processing and Analysis (Q4 - Q7)


Q4. Write a Python program to count the total number of lines in a given file `sample.txt`.

Q5. Write a Python program that reads a file and prints only those lines that contain the
word “Python” (case-sensitive).

Q6. Write a Python program to count the number of words and characters in the file
`sample.txt`.

Q7. Write a program to copy the contents of `sample.txt` to another file `copy_sample.txt`.

Section C: Advanced File Handling (Q8 - Q10)


Q8. Write a Python program to display the last 3 lines of a text file.

Q9. Write a Python program that reads numbers from a file `numbers.txt`, one per line, and
writes only the even numbers to a new file `even_numbers.txt`.

Q10. Create a program that accepts user input (name, age, city) and stores it in a CSV file
`users.csv`. Ensure that every new entry is stored on a new line.

You might also like