CBSE Class 12 Computer Science
Question 82 of 136
Data File Handling — Question 21
Back to all questionsLet the file "Persons.txt" include the following sample text:
Samyukta, Mumbai, 35
Anubhav, Chennai, 28
Aniket, Hyderabad, 42
Sarth, Bangalore, 31
f = open('Persons.txt', 'r')
lines = f.readlines()
for line in lines:
data = line.strip().split(',')
if len(data) >= 3 and int(data[2]) > 30:
print('Name:', data[0], 'Address:', data[1])
f.close() Name: Samyukta Address: Mumbai
Name: Aniket Address: Hyderabad
Name: Sarth Address: Bangalore