Problem Description
Write a python program to create a file and display the contents (dynamic number of lines) and print the files contents in reverse order.
Hint:
1. Create a File
2. Take the input as number of lines to be written into the file
3. Based on the number of lines get the input from the user
4. Get the file name from the user for performing operations
5. Count the number of words in the file and display the number of words in the fie
Input:
1. Filename
2. The number of lines to be written into the file
3. File name to perform operationsCODING ARENA
import os
fname = input()
with open(fname, 'w+') as f:
a=int(input())
for i in range(a):
x=input()
f.write(x+ os.linesep)
f.close()
fnam=input()
for line in reversed(list(open(fnam))):
print(line.rstrip())
f.close()
Test Case 1
Input (stdin)sample.txt 4 eLab an auto evaluation tool in Tamilnadu - eLab eLab will be launched in SWAYM platform soon - eLab eLab is used by 45000+users every year- eLab eLab is a copyleft tool - eLab sample.txt
Expected OutputeLab is a copyleft tool - eLab eLab is used by 45000+users every year- eLab eLab will be launched in SWAYM platform soon - eLab eLab an auto evaluation tool in Tamilnadu - eLab
Test Case 2
Input (stdin)sample.txt 2 eLab an auto evaluation tool in Tamilnadu eLab will be launched in SWAYM platform soon sample.txt
Expected OutputeLab will be launched in SWAYM platform soon eLab an auto evaluation tool in Tamilnadu
No comments:
Post a Comment