मराठी

Write a Python function that displays all the lines containing the word 'vote' from a text file "Elections.txt". For example, if the file contains: In an election many people vote to choose their - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Write a Python function that displays all the lines containing the word 'vote' from a text file "Elections.txt". For example, if the file contains:

In an election many people vote to choose their representative.
The candidate getting the maximum share of votes stands elected.
Normally, one person has to vote oncе.
The process of voting may vary with time and region.
Then the output should be:
In an election many people vote to choose their representative.
Normally, one person has to vote once.

कोड लेखन
Advertisements

उत्तर

def vote():
    f = open("Elections.txt")
    slst = f.readlines()
    for line in slst:
        wordlst = line.split(")
        if "vote" in wordlst:
            print(line)
f.close()
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2024-2025 (March) Set 4

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×