CBSE · 083Class XII · 2025Section C3 marks

Question 29

4 March 2025 · Computer Science (083)

Write a Python function that displays all the lines containing the word 'vote' from a text file "Elections.txt".

Answer

python
def PrintVote():
    F=open("Elections.txt")
    Lines=F.readlines()
    for Line in Lines:
        L=Line.split()
        if "vote" in L:
            print(Line)
    F.close()

Explanation

Opens file, iterates through lines, checks if 'vote' is present as a word, prints line.