Now.
Till now we have implemented all steps until Sep five, so we are going to implement the step six in
this lecture.
Now you might be interested that why we need to step six over here.
Now, the reason for this step six is we need to have a unique text file in our current folder always
because for example, if I just go ahead now and run our code, for example, I'm just going to open
the project file to be able to see the files over here.
Now, if I run it for, for example, for four keys, then hit enter and we will have four students.
You will have in this case, four answers and four questions file.
Now, in the next time, if I just go ahead and call it for three and three, you will see that here.
We have questions for text file also remaining over here.
Now, if I open the answers to file, you will see that we have the answers from the previous quizzes
as well.
Now, to be able to have the only the current files, we are just going to delete all txt files from
the current folder.
Except this counter data takes the file because we need this file.
So that's why I'm not going to touch this.
I will delete only other text files.
Now how can we delete it?
Of course we can delete it by using the OS model.
So before starting our program, I will delete all files from the current directory.
So that's why I will implement step six over here.
So it's going to be like this.
So let me just comment out this one like this.
Then here I will just go ahead and implement the step six.
Now as I mentioned, I need to use OS model to be able to list the text files in the current directory
and delete unnecessary ones.
So I'll just put import OS.
Then here I will implement the logic.
Now to be able to see the all files that we have in the current directory, we are going to use list
their function so it's going to be for file name in OS.
Please dear.
Then we can just go ahead and print out the file names.
Now if I go ahead and run our code, you will see that before asking how many questions will be.
It's just printing out all files to the console that we have in our current directory.
So in the current directory these are the files that we have.
Then I'll just close these files from here.
Then I will select only the text files so we can put if condition over here like this if file name dot
mn sweet dot txt.
So in this case we are just going to print out the file name to be able to see the only text files.
So we'll just stop our program and rerun it.
You'll see that in this case it's printing out only the text files.
Now we are going to delete everything except the counter data.
So that's why I will provide another condition over here.
It's going to be like this.
And so file name starts with, so it's going to start with the country data.
So this is the file name country data.
So to be able to get not equal to this counter data, all I have to do is I have to provide note operator
over here so not equal to country data.
Now if I go ahead and rerun our program, you will see that in this case, we have all text files over
here that we have in the current folder except the country data.
So this means that we can go ahead and easily delete the file from here.
So I will just put os dot unlink function which is going to delete it that file from the current detector.
So then I will put as a parameter file name.
If I just stop our program and rerun our code, you will see that it's going to ask the number of questions
that we have over here.
So I will just put, for example, one and one and hit enter.
You will see that all rest files over here are deleted.
If I just go ahead and open the answer one, you will see that we have only one question, one answer,
and we have only one question for this quiz over here.
Now, if I rerun our code, just remember that the question is capital city of Turkmenistan.
So you will see that this question will change.
So I will just put two and two.
You will see that the question is changed for the questions file one because it had deleted the previous
file and it has created the new file over here.
And the second one also is like this.
And if I just open the answers, we have one B and two D and in the answers tool we have other questions.
Now, if I just rerun our code, for example, for three and three, you will see that the answer is
changing over here.
And the questions also, because we are deleting every time these files from here to be able to have
the new quizzes after generating this quiz project.
Now, with this, we have come to the end of this project.
So in this project we have implemented logic to be able to create separate quiz for the students.
And here we have used the logic.
That we have learned in our previous section how we can use the files in our project.
So hopefully with these comments over here, everything is clear about this project.
Now, if you have difficulties to understand these, I want you to go back and rewatch the videos of
this section one more time.
So hopefully everything is clear.
So see you in the next lecture.