Answer to Question #230789 in Python for Shreya

Question #230789
Write a function in a PYTHON to read the content of a text file “DELHI.TXT” and display all
those lines on screen, which are either starting with ‘D’ or starting with ‘M’.
1
Expert's answer
2021-08-30T01:35:28-0400
def starts_with_dm():
    with open('DELHI.TXT') as file:
        for line in file:
            if line.startswith('D') or  line.startswith('M'):
                print(line)

starts_with_dm()

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