Textfile Program
Textfile Program
Display length five words from file Display number of vowel present in file
1)Open statement(permanent step for any file 1)open statement(permanent step for any file
program) program)
f=open(“abc.txt”,’r’) f=open(“abc.txt”,’r’)
s=f.read().split() s=f.read()
for i in s: c=0
if len(i)==5: for i in s:
print(i) if i.upper() in ‘AEIOU’:
c=c+1
f.close() print(c)
Display line which begin with vowel Word begin or line begin i[0]
1)open statement(permanent step for any file Word end i[-1]
program) Line end i.strip()[-1]
f=open(“abc.txt”,’r’)
s=f.readlines() for word in line.split():
for i in s: this loop is used if word taken from line
if i[0] in ‘AEIOUaeiou’:
print(i)
f.close()
f.read() returns in string format Student must complete the textfile worksheet.
f.readline() returns one line in string format
f.readlines() returns all lines from file