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

Python File Handling Lab Exercises

The document outlines two programming tasks in a Python lab focused on file handling. The first task involves writing a program to sort words from a file into another file in lower-case, while the second task computes the number of characters, words, and lines in a file. Additionally, it includes a grading rubric for evaluating the students' performance on these tasks.

Uploaded by

sekharrao
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)
2 views2 pages

Python File Handling Lab Exercises

The document outlines two programming tasks in a Python lab focused on file handling. The first task involves writing a program to sort words from a file into another file in lower-case, while the second task computes the number of characters, words, and lines in a file. Additionally, it includes a grading rubric for evaluating the students' performance on these tasks.

Uploaded by

sekharrao
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

Python Programming Lab (Skill Oriented Course)

Week-9: File Handling


[Link]: To Write a program to sort words in a file and put them in another file. The output file
should have only lower-case words, so any upper-case words from source must be lowered
Apparatus: Personal Computer
Python 3.12(ver)

Program:
f=open('[Link]','w')
[Link]("Hello Everyone\n")
[Link]("Welcome to python programming session")
with open('[Link]', 'r') as f1:
words = [Link]().lower().split()
print(words)
# Sort the words
sorted_words = sorted(words)
print(' '.join(sorted_words))
# Open the output file for writing
with open('output_file.txt', 'w') as output_file:
output_file.write(' '.join(sorted_words))

Output:

10. Aim: To write a python program to compute the number of characters, words and lines in a
file.

Program:
number_of_words = 0
number_of_lines = 0
number_of_characters = 0
with open("[Link]", 'r') as file:
for l in file:
number_of_words += len([Link]())
number_of_lines += 1
number_of_characters+ = len(l)
print("No of words: ", number_of_words)
print("No of lines: ", number_of_lines)
print("No of characters: ", number_of_characters)

Output:

Department of ECE, LIET


Python Programming Lab (Skill Oriented Course)

Result:

CO\PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PSO1 PSO2
C208.3 3 2 2 - 3 - - - 2 2 2 3

Observation Program Adherence to Viva Total


write up(3M) Execution & Instructions(2M) Voce(2M) (10M)
Results(3M)

Department of ECE, LIET

You might also like