Antonyms

There are 2 two words that we need to understand clearly. Social Distancing and Congregation. Somehow people do not seem to get it clearly. They are exact opposites. And if we follow Social…

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:

Career inspiration from 3D printing professionals

A career in 3D printing can appear challenging. So we’ve asked 9 professionals from the additive manufacturing industry to share their views on the industry, its future and to provide you with some…

The 10 Unique Airbnb Rentals Around the World

From sustainable structures, to cube houses, to dwellings completely comprised of bamboo, here are some ideal properties for even the most serious of design connoisseurs.

The Martian Book Review

The Martian is a science fiction novel, published in 2011 by author Andy Weir, and contains 435 pages. Andy Weir’s first published novel, The Martian, has taken the world by storm since its release…