PYTHON DFH | FUNCTION TO DISPLAY WORDS() WHOSE LENGTH IS LESS THAN 4 CHARACTERS
Write a method/function DISPLAYWORDS() in python to read lines from a text file STORY.TXT, and display & count those words, which are less than 4 characters.
def DISPLAYWORDS():
c=0
file=open('Story.txt','r')
line = file.read()
word = line.split()
for w in word:
if len(w)<4:
c+=1
print(w,end=", ")
print()
print("Total Words of letters less than 4 in file are:",c)
file.close()
#main
DISPLAYWORDS()
op bro bilkul, sax
ReplyDeletetru
Deletefax
Delete