Make Following Program Batch Oriented Using Text Files Input Output Def Phrase Phrase Inpu Q37109102

Make the following program batch-oriented (using text files forinput and output)

def phrase():
phrase = input(“Enter phrase: “)

words = phrase.split(” “)

for i in range(0,len(words)):
if len(words[i])> 1:
print(words[i][0].upper(),end=””)

phrase()


Answer


Please find the code below::

pharseProcess inputtxtoutput.txt 1e def phrase(inputFile): ticClasses7/input.txt try: ovthonProi print(Opening file +inputF

def phrase(inputFile):
try:
print(“Opening file “+inputFile)
writer = open(“output.txt”,’w’);
print(“Writing data to file output.txt”)
with open(inputFile) as f:
content = f.readlines()
content = [x.strip() for x in content]
for phrase in content :
words = phrase.split(” “)
for i in range(0,len(words)):
if len(words[i])> 1:
writer.write(words[i][0].upper())
writer.write(“n”)
print(“Data exported successfully”)
except:
print(“Error in opening file”)
return []
  

phrase(“input.txt”)

output:

Console X terminated> pharseProcess.py [CAUsers Mohammad Shahrukh pening file input.txt Writing data to file output.txt Data

pharseProcess

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.