Week - 7:
1. Write a Python code to merge two given file contents into a third file.
2. Write a Python code to open a given file and construct a function to check for given words
present in it and display on found.
3. Write a Python code to Read text from a text file, find the word with most number of
occurrences.
4. Write a function that reads a file file1 and displays the number of words, number of vowels,
blank spaces, lower case letters and uppercase letters.
PROGRAM – 1:
Aim: Write a Python code to merge two given file contents into a third file.
Tools required:
1. Python distribution.
2. Python IDLE.
Procedure:
1. Open the Python IDLE open the new file editor, and type the following code.
Note: To successfully run the below program file1.txt and file2.txt must exist
in the same folder. Suppose the text files file1.txt and file2.txt contain the
following data.
file1.txt
file2.txt
Below is the program implementation.
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected] 2. Save the program.
3. Execute the program. (RunRun Moduile) or press F5.
OUTPUT:
file3.txt
PROGRAM – 2:
Aim: Write a Python code to open a given file and construct a function to check for given words
present in it and display on found.
Tools required:
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected] 1. Python distribution.
2. Python IDLE.
Procedure:
1. Open the Python IDLE open the new file editor, and type the following code.
Note: To successfully run the below program file1.txt must exist in the same
folder. Suppose the text files file1.txt contain the following data.
Below is the program implementation.
2. Save the program.
3. Execute the program. (RunRun Moduile) or press F5.
OUTPUT:
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected] PROGRAM – 3:
Aim: Write a Python code to Read text from a text file, find the word with most number of
occurrences.
Tools required:
1. Python distribution.
2. Python IDLE.
Procedure:
1. Open the Python IDLE open the new file editor, and type the following code.
Note: To successfully run the below program file1.txt must exist in the same folder.
Suppose the text files file1.txt contain the following data.
Below is the program implementation.
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected] 2. Save the program.
3. Execute the program. (RunRun Moduile) or press F5.
OUTPUT:
PROGRAM – 4:
Aim: Write a function that reads a file file1 and displays the number of words, number of
vowels, blank spaces, lower case letters and uppercase letters.
Tools required:
1. Python distribution.
2. Python IDLE.
Procedure:
1. Open the Python IDLE open the new file editor, and type the following
code.
Note: To successfully run the below program file1.txt must exist in the same
folder. Suppose the text files file1.txt contain the following data.
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected] 2. Save the program.
3. Execute the program. (RunRun Moduile) or press F5.
OUTPUT:
Mr. Mohammed Afzal, Asst.Professor in AIML Dept. @SPHN
Mob: +91-8179700193, Email:
[email protected]