PROGRAMS
PROGRAMS
PROGRAMS
def ISTOUPCOUNT():
file=open('WRITER.TXT','r')
line = file.read()
word = line.split()
cnt=0
for w in word:
if w=='TO' or w=='UP' or w=='IS':
cnt+=1
print("Count of IS, TO and UP is:",cnt)
file.close()
ISTOUPCOUNT()
def AEDISP():
file=open('WRITER.TXT','r')
lines = file.readlines()
for w in lines:
if w[0]=="A" or w[0]=="E":
print(w)
file.close()
AEDISP()
def display1():
count = 0
file = open("INDIA.TXT","r")
for LINE in file:
Words = LINE.split()
for W in Words:
if W == "India":
count = count + 1
print (count)
file.close()
display1()
VI. Write a method in Python to read lines from a text file
MYNOTES.TXT and display those lines which start with the
alphabet 'K'.
def display () :
file = open ('lines.txt', 'r')
line = file.readline ()
while line :
if line [ 0 ] == 'K' :
print (line)
line = file.readline ()
file.close()
display()
VII. Write a method in python to read lines from a text file DIARY.TXT
and display those lines which start with the alphabets P.
def display():
file = open ('lines.txt', 'r')
line = file.readline ()
while line :
if line[0] == 'P' :
print (line)
line = file.readline ()
file.close()
display()
VIII. Write a method in python to write multiple line of text contents into
a text file mylife.txt line.
def write () :
f = open (mylife.txt", 'w')
while True:
line = input ("Enter line:")
f.write (line)
choice = input("Are there more lines (Y/N):")
if choice == 'N':
break
f.close()
write()
IX. Write a function in python to read the content from a text file
"poem.txt" line by line and display the same on screen.
def read_file():
f1 = open(".TXT ",'r')
data = f1.readlines()
for i in data :
print(i)
f1.close()