Class - 12 CBSE Computer Science Important File Handling Questions 2025
Write a Python function that finds and displays all the words longer than 5 characters from a text file "Words.txt".
Python File Handling
6 Likes
Answer
Suppose the file "Words.txt" contains the following text:
The quick brown fox jumps over the lazy dog and runs swiftly through the forest
def display():
file = open("Words.txt", 'r')
content = file.read()
words = content.split()
for word in words:
if len(word) > 5:
print(word, end = ' ')
file.close()
display()
Output
swiftly through forest
Answered By
3 Likes