SET-2_Python_Practical(3-5
SET-2_Python_Practical(3-5
AIM :- A program that reads a text file and counts the number of words in it.
Source Code:
# Initialize a counter to store the total number of words
count = 0
# Open the file in read mode (change the file path as per your file location)
for line in f:
word = line.split()
# Add the number of words in the current line to the total count
count += len(word)
f.close()
OUTPUT :
Source Code:
import csv # Import the CSV module for reading CSV files
Source Code:
import pandas as pd # Import the pandas library for handling Excel files
def read_excel_and_display(file_path):
try:
df = pd.read_excel(file_path)
except FileNotFoundError:
print(f"Error: File not found at '{file_path}'. Please check the path and try again.")
except Exception as e:
read_excel_and_display(file_path)
OUTPUT :