CBSE Class 12 Computer Science
Question 91 of 136
Data File Handling — Question 30
Back to all questionsLet the file "logs.txt" include the following sample text:
[2022-04-15 10:00:00] INFO: Application started
[2022-04-15 10:05:00] ERROR: Database connection failed
[2022-04-15 10:10:00] WARNING: Disk space low
[2022-04-15 10:15:00] INFO: User logged in: username=john, ip_address=192.168.1.100
file_name = input("Enter the filename: ")
f = open(file_name, 'r')
lines = f.readlines()
for line in lines[::-1]:
print(line.rstrip())
f.close()Enter the filename: logs.txt
[2022-04-15 10:15:00] INFO: User logged in: username=john, ip_address=192.168.1.100
[2022-04-15 10:10:00] WARNING: Disk space low
[2022-04-15 10:05:00] ERROR: Database connection failed
[2022-04-15 10:00:00] INFO: Application started