CSC 171 - Introduction to Computer Programming

Lab Assignment #19 - Writing Output to a Text File

Due Thursday, November 16, 2023

We have already seen writing to text files, which we start by opening a file for output:

my_file = open("my_file.txt", "w")

If a file by that name already exists in the directory in which we are planning to save that, the old file will be lost.

We can write two line in that file by writing:

print("First line", file=my_file)

print("Second line", file = my_file)

After we finish writing in the file, we can close it by writing:

temp_file.close()

Write a program that will read in lines of text and it will then write these to a file. Before you close the file, write the number of lines that you wrote in the file.

Submit the program and the output file along with a flowchart and with pseudocode for the program

[Back to the Lab Assignment List]