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::
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:
pharseProcess