- [Instructor] In this self check exercise,
we'd like you to create your own text file called grades.txt
and we'd like you to write three records of information
consisting of a fake student ID,
a last name, and a letter grade.
So here's some sample records
that you can write into the file.
So go ahead and pause the video and use a with statement
to actually create the file
like we did in the preceding video.
When you're done doing that,
come back here to see my answer.
Okay, so all we're going to do,
like we did in the preceding video,
is open, in a with statement, the grades.txt file
which will be written into the current folder
wherever you are executing the statement.
We're going to open that file for writing.
So, again, if that file already exists,
it will be overwritten by this
with statement opening the grades.txt file.
We're going to treat the resulting file object
as the name grades, the variable name grades,
or interact with it through that variable.
And here we're writing out the three records of information
we specified in the problem statement.
So we'll go ahead and execute that.
And, again, depending on whether
you're a macOS or Windows user,
you can execute the exclamation point cat
or exclamation point more command
followed by the name of your file to see its contents.
So let me go ahead and do that here on my Mac,
and as you can see,
indeed the file was created
with the three records of information
that we wrote in the with statements suite.