Problem Description
Write a python program to create a file and display the count of all the characters in the file
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. File name to be searched
Input:
1. Filename
2. The number of lines to be written into the file
3. File name
Output:
Display the count of all characters in the fileCODING ARENA
fname = input()
a=int(input())
with open(fname, 'w') as f:
for i in range(a):
x=input()
f.write(x)
f.close()
fnam = input()
infile = open(fnam, 'r')
characters = 0
for line in infile:
for i in range(len(line)):
if(line[i].isalpha()):
characters = characters + 1
print(characters)
Test Case 1
Input (stdin)sample.txt 2 eLab is an auto evaluation tool This file program in eLab will show you the count of words in the file except numbers like 1234567890 sample.txt
Expected Output99
Test Case 2
Input (stdin)sample.txt 3 eLab is an auto evaluation tool This file program in eLab will show you the count of words in the file except numbers like 1234567890 2017 2016 2015 2018 eLab sample.txt
Expected Output103
No comments:
Post a Comment