Report File
Report File
Write a python script to take input for a number and print its
factorial?
1. Push
2. Pop
3. Traversal
4. Exit
Enter your choice 1
Enter bcode 101
Enter btitle python
Enter price 254
1. Push
2. Pop
3. Traversal
4. Exit
Enter your choice 3
(‘101’, ‘python’, ‘254’)
1. Push
2. Pop
3. Traversal
4. Exit
Enter your choice
Write a python program to read a file named “article.txt”, count
and print the following:
(i). length of the file(total characters in file)
(ii).total alphabets
(iii). total upper case alphabets
(iv). total lower case alphabets
(v). total digits
(vi). total spaces
(vii). total special characters
def count():
a=0
ua=0
la=0
d=0
sp=0
spl=0
with open("story.txt") as f:
while True:
c=f.read(1)
if not c:
break
print(c,end='')
if((c>='A' and c<='Z') or (c>='a' and c<='z')):
a=a+1
if((c>='A' and c<='Z') or (c>='a' and c<='z')):
a=a+1
if(c>='A' and c<='Z'):
ua=ua+1
else:
la=la+1
elif(c>='0' and c<='9'):
d=d+1
elif(c==' '):
sp=sp+1
else:
spl=spl+1
print("total alphabets ",a)
print("total upper case alphabets ",ua)
print("total lower case alphabets ",la)
print("total digits ",d)
print("total spaces ",sp)
print("total special characters ",spl)
# function calling
count()
Write a python program to read a file named “story.txt”, count
and print total words starting with “a” or “A” in the file?
def count_words():
w=0
with open("story.txt") as f:
for line in f:
for word in line.split():
if(word[0]=="a" or word[0]=="A"):
print(word)
w=w+1
print("total words starting with 'a' are ",w)
# function calling
count_words()