Now that we've seen how to create our own custom classes, we're finally ready to build the Quiz Game.
Now this game is going to be a simple, True / False game,
so a question will be asked to the user and they'll select True or False,
and then we'll tell them if they got it right or wrong and give them a score.
Now to begin, the first step you'll need to do is to download the zip file with all the starting code
from our Course Resource website.
And once you've extracted the actual folder, quiz-game-start from the .zip file,
then we're ready to go ahead and open it using PyCharm.
In PyCharm we're going to click Open,
and then we're going to navigate to the place where we have our quiz-game-start, which in my case is
in the Downloads folder.
PyCharm should automatically configure the latest version of Python you've got installed as the interpreter.
So you can go ahead and close these pop-ups.
And if we open up our quiz-game-start folder, you can see we have four files, data, main, question_model,
and quiz_brain.
And over the course of the next few lessons, we're going to be writing the code in all of these files
so that we end up creating our Final Quiz Project.
The first task that we have is to create a model for a question in our quiz.
If we had a Question object, well, what kind of attributes should it have?
It might have a text attribute for the question text, and it might also hold an answer attribute,
which is going to be the correct answer to that question.
Now these two attributes should be initialized with a value when a new_q object is created from
this class.
So for example, if our first question was 2 + 3 = 5, which we know the correct answer
should be True,
well, then we might write the code like this to actually initialize a new_q object.
And when this initialization goes through, the constructor code inside the Question class will take these
two pieces of data and then add them to the corresponding attributes, the text and the answer.
And so our new_q object will have both of these attributes initialized with a value
when a new_q object is being created. Inside your project, go over to the question_model.py file,
and go ahead and create a new class called Question,
and that Question class should have an __init()__ method which will initialize two attributes the text and
the answer, just as you've seen in the previous slides.
Pause the video and see if you can complete this challenge by creating this class.
All right.
So we know that to create a class we first have to use the class keyword.
And then in our case the name of the class is going to be called Question because we're modeling what
a question would be like in our game.
We know that each of these questions have two attributes a self.text and a self.answer,
and those two attributes are going to be initialized when we create a new_q object,
so we need the __init()__ function in here.
And we're pretty much going to use the autofill,
so once you write 'def', and then you write 'init', you can see it in the dropdown list,
and then just hit Enter, and the code will be inserted automatically.
This way you don't have to remember the exact order of the parentheses, or where to put the colon, et cetera.
et cetera.
Now inside the __init()__ function, we're going to set up two attributes
s we said, one is going to be called text and one is going to be called answer.
And if we want to create an attribute we have to use this syntax self. and then the name of the attribute,
because eventually when we create a new object from this class, say a new_q object, then we're
going to be passing in these two items a piece of text, which is going to be the question, and then
either True or False as the answer.
And then later on, if we wanted to access the text, then we would say new_q.text.
Now of course, at the moment these are all yellowed out because it seems to have no effect.
There's no way of receiving a value for each of these attributes.
And to do that we have to add some inputs inside the init function.
So let's just call it q_text and q_answer.
You can of course call these parameters anything you want, but the important part is you set the self.text
to that first value, and the self.answer to the second value.
So now when we actually go ahead and print this new_q.text object, like we have here, then
it will go ahead and actually fetch this value into the output.
If you go to Run and then Run and then select question_model, you can see that is what gets printed
in the console.
Let's delete those two lines.
And now we have completed our first task which is creating our Question class from scratch.