Answer to Question #189484 in Python for Vtajesh

Question #189484

Write a method/function SHOw_TODO0 in python to read contents from a text


file ABC.TXT and display those lines which have occurrence of the word "TO" or

DO"


For example IMPORTANT : If content TO of the NOTE file is THAT SUcCESS IS THE REsULT OF

HARD wORK. WE ATI. ARE EXPFcTED TO DO HARD WORK. AFTER


ALL EXPERIENCE cOMES FROM HARDwORK.


The method/funetiom should displays


THIS IS IMPORTANT TO NOTE THAT SUCCESS IS THE RESULT


OF HARD wORK.

WE ALL ARE EXPECTED to do hard work


1
Expert's answer
2021-05-05T10:29:07-0400

Fixed:


def SHOw_TODO0():
    ABCFile = open('ABC.txt', 'r')
    while True:
        # Get next line from file
        line = ABCFile.readline()
        if not line:
            break
        else:
            if " to " in line.lower():
                print(line.strip())
            elif " do " in line.lower():
                print(line.strip())
 
    ABCFile.close()




SHOw_TODO0()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS