Q. Write a program to search the names and addresses of persons having age more than 30 in the data list of persons.

Answer :-

Let us consider the content of the file to be like this -

Name, address, age

f = open("Pathwalla.txt",'r')
data = f.readlines()
for i in data :
    age = i.split(",")
    if int(age[ 2 ]) >= 30 :
        print(age[0])

Let us consider the content of the file to be like this -

Path ,India ,44
Walla ,USA ,12
Portal ,UK ,5
Express ,UAE ,30

Output :-

Path 
Express 

>>> 


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Split kyun kiya

    ReplyDelete
    Replies
    1. Because after spliting we will get list like ["Path" , "india" , "44"], So from list we can directly get age.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post