6.
Write a program to count and display the occurence of word ‘why’ in the file.
with open('p2.txt','r')as fh:
c=0
for i in fh.readlines():
for word in i.split():
if(word.lower()=='why'):
c=c+1
print('total number of why =',c)
7.
Write a program to count the words starting with vowel.
with open('p2.txt','r')as fh:
c=0
v='aeiouAEIOU'
for i in fh.readlines():
for word in i.split():
if(word[0] in v):
c=c+1
print('total number of words starting wiht vowel =',c)
8.
Write a program to display the longest line of the file.
with open('p2.txt','r')as fh:
longest=""
r=fh.readlines()
for line in r:
if len(line)>len(longest):
longest=line
print("longest line's length=", len(longest))
print(longest)
9.
What will be the output of the following code?
fh=file("poem.txt","r")
size=len(fh.read())
print(fh.read(5))
fh.close()
Ans. No output
10.
What will be the output of the following code?
fh=open("poem.txt","r")
s1=fh.read(28)
print(s1)
fh.close()
Ans. Why?
we work, we try t