Dec-11-2018, 04:03 AM
In Python, Write a program that reads a file containing a text (input.txt). Read each line and send it to the output file (output.txt), preceded by line numbers. If the input file is:5 pts
Mary had a little lamb
Whose fleece was white as snow.
And everywhere that Mary went,
The lamb was sure to go!
Then the program produces the output file
/* 1 */ Mary had a little lamb
/* 2 */ Whose fleece was white as snow.
/* 3 */ And everywhere that Mary went,
/* 4 */ The lamb was sure to go!
prompt the user for the input and output file names.
So this is what ive written so far but it has a file not found error no matter wether I put the full location or file name, any ideas would help and double check to make sure I got the rest proper please and thank you!
Mary had a little lamb
Whose fleece was white as snow.
And everywhere that Mary went,
The lamb was sure to go!
Then the program produces the output file
/* 1 */ Mary had a little lamb
/* 2 */ Whose fleece was white as snow.
/* 3 */ And everywhere that Mary went,
/* 4 */ The lamb was sure to go!
prompt the user for the input and output file names.
So this is what ive written so far but it has a file not found error no matter wether I put the full location or file name, any ideas would help and double check to make sure I got the rest proper please and thank you!
#prompts user for input/output file name inputFileName = input('Input file name') outputFileName = input('Output file name') #opens the input out files inputFile = open(inputFileName, "r") outputFile = open(outputFileName, "w") total = 0 #to copy and add line numbers and close the files for line in inputFile: string = inputFile.readlines() total = total +1 outputFile.write("/*",total ,string, "*/") #closes the files inputFile.close() outputFile.close()