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

Lab 04 B

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 2

PFP - Labwork 04

Q1 (2.5 marks). Write a program that performs the following tasks:


1. Write a function in Python to read the content from a text file "poem.txt" line by line and
display the same on-screen.
Expected Output:

2. Write a function in Python to count the number of lines from a text file "story.txt," which is not
starting with an alphabet "T."
Example: If the file "story.txt" contains the following lines:
A boy is playing there.
There is a playground.
An airplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.
Expected Output:

Q2 (2.5 marks). Write a program that performs the following tasks:


1. Write a function in Python to count and display the total number of words in a text file.
Expected Output:

2. Write a function display_words() in Python to read lines from a text file "story.txt" and display
those words less than 4 characters.
Expected Output:

Q3. (2.5 marks). Write a program that performs the following tasks:
1. Write a function in Python to count uppercase characters in a text file.
Expected Output:

2. Write a function in Python to count the words "this" and "these" present in a text file
"article.txt". [Note that the words "this" and "these" are complete words]
Expected Output:

Q4. (2.5 marks). Write a program that performs the following tasks:
1. A text file named "matter.txt" contains some text, which needs to be displayed such that a
symbol "# separates every next character." Write a function definition for hash_display() in
Python that would show the entire content of the file matter.txt in the desired format.
Example :
If the file matter.txt has the following content stored in it :
THE WORLD IS ROUND
The function hash_display() should display the following content :
T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#
Expected Output:

2. Aditi has used text editing software to type some text. After saving the article as WORDS.TXT,
she realized that she had wrongly typed alphabet J in place of the alphabet I everywhere in the
article.
Write a function definition for JTOI() in Python that would display the corrected version of the
entire content of the file WORDS.TXT with all the alphabets "J" to be displayed as an alphabet "I"
on screen.

Note: Assuming that WORD.TXT does not contain any J alphabet otherwise.

Example:
If Aditi has stored the following content in the file WORDS.TXT:
WELL, THJS JS A WORD BY JTSELF. YOU COULD STRETCH THJS TO BE A SENTENCE
The function JTOI() should display the following content:
WELL, THIS IS A WORD BY ITSELF. YOU COULD STRETCH THIS TO BE A SENTENCE.

Expected Output:

You might also like