96 Years Old and Healthy During a Pandemic

My dad keeps asking about the thing that’s on TV, the thing he can’t pronounce until I write it phonetically. He has a hard time remembering, so I have numerous notes lying about that I’ll grab for…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Making Quizzes Using Python

There are so many resources available for making the multivariable applications that are possible with python, that even a simple google search with Python + whatever you are looking for, will yield an impressive amount of results.

Perhaps this is one of the reason Python is growing at such a rapid pace.

Using Python, we can make pretty simple Tic-Tac-Toe games, as well as games that are a bit more complicated like Blackjack using object oriented programming. There are enough blog post and Youtube videos out there that I won’t cover in this blog.

However, I will cover is how to make quizzes in python, whether the built in def function built into python or using the Class from Object Oriented Programming, albeit they both will be rudimentary.

I looked at two ways to make a translation based quiz: one using Python dictionary key:value relationship and the other using list in object oriented programming. I found one to be better suited for making quiz than the other, as you will see.

Now for the creation of the quizzes. First, we will tackle the dictionary based quiz using Python built in def function. I will post the whole codes below (it’s a very simple quiz) and then go line by line, what is actually happening.

This method is relatively easy to make. First we define a main function. Then we create the dictionary with words we want to translate. The print lines take in user input such as a player’s name, in addition to how well they did in the quiz. The main quiz components come from the second define function: quiz with the actual dictionary we created as the parameter. Setting up score as 0, because you start with zero points. Then create a for loop functions for using key,value pair and iterate through the dictionary we created earlier. If user input of definition matches up exactly with the input put into the dictionary, then a score of 1 is added. If they are wrong, a print statement of ‘Sorry you are incorrect, the correct answer is [ ]’ is shown.

However, there are two big issues with this. One is that if you forget to match the value exactly or mispell even by a single character, it will mark you incorrect. In addition to that, it will end the quiz completely.

As you can see above, I put my name as my initial, then proceeded to answer the questions. For the third word, I forgot to put a space and it marked me as wrong. But worst of all, it ended the quiz so I couldn’t even try to answer the other two questions.

Bumping into this problem, I realize this is not an effective method to create a quiz. So then I decided, let’s try out Object Oriented Programming, and use the Class based method to see if the quiz can be better:

I bolded the answers I input here. As you can see, it is much easier to put answers in and getting an incorrect answer does not stop the quiz. However, there is still the issue that this quiz does not tell you which question you got incorrect and what the correct answer is- which could be problematic if we had more than two answer choices per questions.

The next step would be to figure out a way to display the incorrect answer while still continuing the quiz. In addition, perhaps create a web-scraper application that can take in words from any translation service and input them into the function so as to automate the process. This will significantly reduce time it will take to make new dictionary based games.

As you can see, python can be used for more than just creating complicated machine algorithms. Sometime, simple can be fun.

Add a comment

Related posts:

GSoC 2019 with CloudCV

I was waiting for 6th May 2019, when the result of students selected for google summer of code were announced. Felt exciting & overwhelmed to see my name on the much awaited list. During the…

2014 signaled the year of a new me. Let 2019 signal a new year for you.

It seems that nowadays more than ever, people are finding excuses to put off plans for the future. Most of us millennials are in the same boat. We want for the same things in life that our parents…

Hello Everyone!!

My offer letter from Oasis was released.I was really excited when I got offer letter from OASIS as it’s my first internship. I felt much thrilled about my work.I got offer letter as JAVA DEVELOPMENT…