Entrance Announcement
MICTE 2080
2080 Magh 07
User:Niraj/Teaching-4
Jump to navigation
Jump to search
Teaching lesson plan 4 Subject: Python programming
Date: 18 Jan 2024
Time: 60 minutes
Period: 3rd
Teaching Item: Exploring Input and Output in Python: Reading and Writing Text Files
Class: Bachelor
Objective: By the end of this lesson, students will be able to:
- Understand the basics of input and output operations in Python.
- Read data from text files using various methods.
- Write data to text files using different techniques.
Materials Needed:
- Python interpreter or IDE
- Projector for demonstration
Introduction (5 minutes):
- Introduce the concept of input and output (I/O) operations in Python.
- Explain that input refers to obtaining data from external sources, while output refers to displaying or storing data.
- Discuss the importance of reading from and writing to text files as common I/O tasks in Python programming.
Reading Text Files (15 minutes):
- Explain the process of reading data from text files in Python.
- Discuss different methods for reading text files, such as using
open()
function withread()
,readline()
, orreadlines()
methods. - Demonstrate each method with examples, emphasizing their differences and use cases.
- Discuss error handling techniques, such as using
try-except
blocks, when reading files to handle exceptions likeFileNotFoundError
.
Writing Text Files (15 minutes):
- Explain the process of writing data to text files in Python.
- Discuss different modes for opening files, such as
"w"
(write mode),"a"
(append mode), and"r+"
(read/write mode). - Demonstrate how to open a file in write mode and use the
write()
method to write data to it. - Discuss best practices for writing to files, such as using context managers (
with
statement) to automatically close files after writing. - Show examples of writing multiple lines of text to a file and appending data to an existing file.
Practical Exercises (10 minutes):
- Provide students with exercises to practice reading from and writing to text files.
- Encourage them to create their own text files and perform various I/O operations on them.
- Circulate around the classroom to provide assistance and guidance as needed.
Conclusion (5 minutes):
- Summarize the key points covered in the lesson: input and output in Python, and reading and writing text files.
- Reiterate the importance of mastering these skills for handling data in real-world programming scenarios.
- Encourage students to continue practicing and experimenting with reading from and writing to text files to strengthen their understanding.
- Invite questions from students and address any remaining doubts or confusion.
Assessment:
- Informal assessment through observation of students' participation in discussions and activities.
- Review students' completed exercises or tasks to assess their understanding of reading and writing text files in Python.