DIY:Programming Tutorials EP07 - Creating a Quiz game in Python.

Greetings to all;

Congratulations to you, if you’ve found yourslef on my blog you are in to gain lots of cool and fun stuffs :) that might come in handy, welcome once again to another edition of my coding tutorials. For todays edition, i thought of creating a fun quiz using python. The question’s and answers are programmed into the computer, so basically the person taking the quiz needs to tru and get the answers right. They would be based on hive and mainly on this community. I’ll show you how its done. At your own pase you can try it out. You can even go ahead and customize it with your own questions.

To start the quiz, there is need to you welcome the audience or peoples going to participate in the quiz, so i start by using the print function to print the phrase “Welcome to HIVE Quiz”. And then i went on to ask the user if he or she has the intention of playing. This is accomplished by using a funtion playing which is set to input(“Are you interested in palying “). This space given betwen the playing and will allow the user enter his input as wether yes or no.

Now i will use the IF clause such that when a user enters yes, he can continue to play the quiz game and if he enters no, the code is terminated. So if playing is not equal to yes, in programming not equal to can written as !=. Then quit(). This would end the code if the input is not yes.

Lets print “lets play” if the users enters yes. Mind you if you enter no, the code will be terminated and you will not see the ”lets play” being displayed by the computer.


Output of the code;

From the output, you can see as I entered yes it prints lets play to begin the quiz game


Output if no was inputed;

From the output, you can see as I entered no the code terminates


For the first question, i asked ”what does DIY mean? “. I hope you understand why i have left a space the ? and the “.? This is to allow the user enter his answer.

Now its time to feed the computer with the answer to the question. We will be using the IF CLAUSE so that if question = ”DO IT YOURSELF tell the user he is correct. so now the computer knows the answer as DO IT YOURSELF. so if the user types exactly the same thing the prompt will be Correct. if you mix caps with small letters it will wont work because python programming language is case sensitive.

We bring in the Else stament so that if anything apart from the amswer provided is inputed by the user it should tell him Incorrect

For the second question, all we need to do is to repeat all what we did for the first question. But the questions needs to change this time around the qestion would be what is Diyhub about?.

We again use the if clause to feed the answer to the computer such that if question = all about do it yourself print correct, else print incorrect.

The third question, following the same procedure but changing the previous question we have How many categories of post does Diyhub discover?.

Using the if clause, if question = 3 then print correct if not using the else function print incorrect.

For the final and last question, we will be required to name the categories of post they discover. The two statements if and else clause are used simultaneously to accomplish that. The if will feed the computer with the amswer creative, crafting, home and gardening

Whiles the else stament will tell the user he is incorrect if any input apart from that list is entered.


Now we run entire code;

From the outputs given, you can see as I entered yes the game began where i entered all the right answers to the questions i was told correct by the computer


Now lets try an output code where i enter no;

From the output, you can see as I entered no the game ends and i dont see the quiz to answer


Well that will be all. And thank you for stopping by see you all on the next on. If you have any questions feel fry to ask i will reply you as soon as possible. Thank you

H2
H3
H4
3 columns
2 columns
1 column
10 Comments
Ecency