# Python Tutorial | Python Data File Handling 7

### Question: 6Python program to read the contents of the file “story.txt”. Further, count and print total digit in the file.Sol:

```def count_digit():
d=0
with open("story.txt") as f:
while True:
if not c:
break
print(c,end='')
if(c>='0' and c<='9'):
d=d+1
print("total digits  ",d)
#function calling
count_digit()```

### Question: 7Python program to read the contents of the file “story.txt”. Further, count and print total vowels in the file.Sol:

```def count_vowels():
v=0
vowels="aeiouAEIOU"
with open("story.txt") as f:
while True:
if not c:
break
print(c,end='')
if(c in vowels):
v=v+1
print("total vowels  ",v)
function calling
count_vowels()```

### Question : 8Python program to read the contents of the file “story.txt”. Further count and print total consonants in the file.Sol:

```def count_consonants():
c1=0
vowels="aeiouAEIOU"
with open("story.txt") as f:
while True:
if not c:
break
print(c,end='')
if((c>='A' and c<='Z') or(c>='a' and c<='z')):
if not (c in vowels):
c1=c1+1
print("total consonants ",c1)
function calling
count_consonants()```

### Question : 9Python program to read the contents of the file “story.txt”. Further count and print the following:#total length#total alphabets#total vowels#total conbsonants#total non alpha charactersSol:

```def count():
v=0 #vowels
le=0 #len
c1=0 # consonents
c2=0 # non alphabetic characters
a=0
vowels="aeiouAEIOU"
with open("story.txt") as f:
while True:
if not c:
break
print(c,end='')
le=le+1
if((c>='A' and c<='Z') or(c>='a' and c<='z')):
a=a+1
if (c in vowels):
v=v+1
else:
c1=c1+1
c2=c2+1
print("total vowels  ",v)
print("total consonants ",c1)
print("total alphabets ",a)
print("total chars which are not alphabets ",c2)
print("length = ",le)
function calling
count()```

### Question: 10Python program to read the contents of the file “story.txt”. Further, count and print total spaces in the file.Sol:

```def count_space():
s=0
space=" "
with open("story.txt") as f:
while True: