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

Python File Exercises

The document provides 5 examples of functions to write in Python related to text file processing: 1) count lines starting with a letter, 2) count total words, 3) find occurrences of a word, 4) display words under 4 characters, 5) calculate grades and assign a letter based on percentages.

Uploaded by

glllsnn
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)
10 views1 page

Python File Exercises

The document provides 5 examples of functions to write in Python related to text file processing: 1) count lines starting with a letter, 2) count total words, 3) find occurrences of a word, 4) display words under 4 characters, 5) calculate grades and assign a letter based on percentages.

Uploaded by

glllsnn
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/ 1

1-) Write a function in python to count the number of lines from a text file "story.

txt" which
is 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 aeroplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.

2-) Write a function in Python to count and display the total number of words in a text file

3-) Write a function in Python to read lines from a text file "notes.txt", to find and display the
occurrence of the word "the".

For example: If the content of the file is:


"India is the fastest-growing economy. India is looking for more investments around the
globe. The whole world is looking at India as a great market. Most of the Indians can foresee
the heights that India is capable of reaching."

4-) Write a function display_words() in python to read lines from a text file "story.txt", and
display those words, which are less than 4 characters.

5-) Grade Calculater: We read the file and sent each line to grade_calculate

final_grade= grade1 * (3 / 10) + grade2 * (3 / 10) + grade3 * (4 / 10)

90 letter = "AA"
>= 85 letter = "BA"
>= 80 letter = "BB"
>= 75 letter = "CB"
>= 70 letter = "CC"
>= 65 letter = "DC
>= 60 letter = "DD"
>= 55 letter = "FD
else letter "FF"

You might also like