Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
731 B
2
Indexable
Never
# Part A: Writing a function definition
def lineNumber(num, sentence):
    return f'{num:03}. {sentence}'

# Part B: Processing a text file
def main():
    input_file_name = input("Input file name: ")
    output_file_name = input("Output file name: ")

    with open(input_file_name, 'r') as infile, open(output_file_name, 'w') as outfile:
        lines = infile.readlines()
        total_letters = sum(len(line.strip()) for line in lines)
        for i, line in enumerate(lines, start=1):
            outfile.write(lineNumber(i, line))
        outfile.write(f'\nThe total number of letters in the file {input_file_name} is {total_letters}.\n')

    print("End of program")

if __name__ == '__main__':
    main()