-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ab4efb
commit 5227245
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#Q. 98: | ||
|
||
#Count Number(File Handling) | ||
|
||
#Write a python program to create a file and display the contents (dynamic number of lines) and count the numbers in the file and display the count. | ||
#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. Input the file name to perform the operations | ||
#Input: | ||
#1. Filename | ||
#2. The number of lines to be written into the file | ||
#3. File name | ||
#Output: | ||
#The total count of the numbers in the file | ||
|
||
|
||
def spliter(data): | ||
return list(data) | ||
|
||
name = input() | ||
size = int(input()) | ||
file = open(name,"w") | ||
for i in range(0,size): | ||
data = input() | ||
file.write(data + "\n") | ||
file.close() | ||
c = 0 | ||
name = input() | ||
file = open(name,"r") | ||
data = file.read() | ||
data = str(data).split() | ||
l = len(data) | ||
for i in range(0,l): | ||
res = spliter(data[i]) | ||
for j in res: | ||
if j.isdigit() and j != 0: | ||
c = c + 1 | ||
print(c) |