This is a continuation of my previous article entitled Cat COLABs With SPYDER. If you haven’t read about it, click this link.
This is the version 2.0 of my recent python quiz game. I added a lot of features and revised some parts which I will discuss in this article.
So the first thing I changed is the way I stored the questions and answers. In the first version, I used a dictionary. In this latest version, I also used a dictionary but in a slightly different approach.
I made an object named QandA. It is basically a list of dictionaries which comprises of 2 key:value pairs each; 1 for the question and the other for the answer. I figured, it is much easier to call on the questions and answers this way.
The twists and challenges for me as the programmer:
- Incorporate CRUD in the program
- Add a feature that would display the scores of the previous players of the game
- Input validation
For those who are not yet familiar with this term, here is what it stands for: CReate-Update-Delete
For this quiz, it basically means that the program should allow an option for the user to add, delete, or replace an item in the quiz.
Let’s start!
I decided to add 2 kinds of users for the program. First option being the Player and the second being the Moderator which will give access to the user to modify the quiz.
This is what the start of the program looks like. The user is given an option to play or modify the game. When choosing the Moderator, the program will ask whether or not the user wants to update the question bank. Typing ‘no’ gets you back from the start as shown in the screenshot above.
Typing ‘yes’ will give the Moderator access into deleting, replacing, and adding questions. I won’t be discussing the codes for this but you can access it through the Github link at the last part.
If the user opted for the ‘delete’ option, he will choose which item number to remove. Then the program will print the new set of QandA.
When the user opted for the ‘add’ option, the program will ask the user to type the question according to the sample format, then the correct answer after that. The program will print the new set of QandA.
The syntax for the ‘replace’ option is just the combination of both the delete-add options.
For the second half of the twist and challenge, I created 2 empty list that would enable the program to append the names of the users and their corresponding scores. Then at the end of the game, will loop all the objects inside the lists.
This is the Score Board where the previous players and their corresponding scores are posted. During the game, only 2 players tried out.
Since there are now more interactions between the users and the program, there is a need of data input validation to avoid the program from crashing and displaying errors during the game proper.
In handling those errors, some basic syntax were used such as the ‘try-except’, conditional statements and looping. While there are more effective error handling techniques that can be used, the stated are the most common and handy for beginner like me.
For some who are interested and curious about the program that I built, you can access it in this link.
Disclaimer: This project wouldn’t be possible without the FTW Foundation who continuously helps and encourages women to take their career path in technology, and our mentor who constantly challenges us into building codes, and my friends who were almost like a walking Spyder that can instantly run codes inside their minds.