Thursday, 14 November 2019

Write a Python program with method/function DISPLAYWORDS() to read lines from a text file STORY.TXT, and display those words, which are less than 4 characters.

def displayword():
     file=open("D:\story.txt")
     line=file.read()
     c=0
     word=line.split()
     for w in word:
          if len(w)<4:
               print(w)
     file.close

#main program
displayword()

input
file name: story.txt

then he stooped and 
learned his head against the
wall and without a word he made
a gesture to us with 
his hands.

output
============== RESTART: C:/Users/Student/Desktop/12cs/fi-22.py ==============
he
and
his
the
and
a
he
a
to
us
his
>>> 

No comments:

Post a Comment