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


Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS