Welcome to today's bonus example.
We're going to create a daily journal app which behaves like this.
So let me demonstrate you the output of the program.
The program first asks the user to enter today's date.
So let's enter 2022 and ten, maybe 20.
You press enter the program, asks you again to rate your moods the mood you had today from 1 to 10.
Let's answer eight, for example, and then you write the thoughts of the day.
So let's write something like it was a good day in general.
No big events happened.
Press enter.
That's it.
Now, if you go to the Journal Directory, which I had created earlier, so you need to create this
directory manually.
And then inside this, a file was generated by Python.
So that's the contents of our.
Program.
So every new day that you execute the program, it will create a new file.
So ten days, ten files, and each file is going to contain the date of the day as a file name.
Yeah, let's write the program.
So, first of all, we want to ask the user to enter today's date.
So we need an input function for that with the string.
Next, we ask the user to rate their mood.
So another input function.
So we've got two variables data and mood.
Then we ask the user again to just write down their thoughts.
So yet another input function.
I'm writing here, I'm having a backslash and to create a break line.
You saw that when I entered the inputs here as a user, the input was written in the next line.
So a break line was created by this backslash.
N By the way, this output was executed from.
A script which is somewhere here, but I don't want to show the script to you in the beginning.
So now we want to recreate that program again.
Once we get the inputs, then we want to create a file using that as a name for the file.
So let's write with open.
Date.
So the file, the actual file path would be something like
dot, dot, slash.
Journal.
Slash and then the date
and close and curly quotes and this would be an F string.
So let me close the string here and make it an F string.
And these two dots, as you know, are when my python file is inside an inner directory.
In my case, it's inside bonus.
So bonus and journal are in the same directory, so the file has to go up one level with these dots
and then points to journal and then date dot text.
So this file will be created in right mode.
And in the next line, which is indented.
We say, fine.
That's right.
What do we write here?
So the content would have the rates on top.
So that means this would be the mood.
Then we don't close the file we write.
The journal in the file.
All the text or whatever you call it.
So the thoughts of the user.
Let's rename it to false actually does make more sense.
And yeah, I'll run the script now, so make sure that a journal directory exists and it reflects that.
Path there.
Journal.
I'll delete the existing file and run the script.
Today's date 2022 2010.
Enter.
How do you rate?
Let's try seven.
Nice day in general.
It was fun.
Press enter.
And let's check journal.
So that's the outputs.
We're close.
Seven is the rate and is not so well formatted.
So we want to have like one two break lines between these two.
So in that case, we want to go back to the Python file.
And after Moody's, which is seven, seven, is a string.
So it comes as a string from the input function.
So basically, mood is a string.
And if you do mood.
Plus backslash.
GN You get seven backslash N But this is the output in the command line, so if you use a print function.
Backslash, and it's printed out as an actual brake line.
So now we have a brick line here when you just call the expression like that, without printing in the
python console, you always get the row, the row string like that.
So we can use that expression or we can also do two times that.
So we have to break lines one, two, so let's say plus two times backslash ends.
So that is the equivalent of if you set plus backslash n.
Plus another backslash.
N And so you get the same behavior you see here and there.
We have these break lines so that we can try the code again, this time with another date going to 21.
Ten Press enter.
How do you rate?
Try nine this time.
Great day.
Press Enter Process Finished.
A new file was generated as you see here.
And there's the content as we expected.
And that's our final code.
So the key point to take here is that the with contacts manager keeps the file open and anything that
is indented here is working on the open file so you can write and write and write text over over again.
Everything will be appended to appended to the text file.
So thanks for following this.
I'll talk to you later.