Introduction: Using Python to Learn Non-English Keyboard Layouts

Hi, I’m Julien! I am a computer science student and today I am going to show you how you can use Python to teach yourself the keyboard layout of a non-English language. A lot of language learning happens online nowadays, and one thing people can really struggle with is learning where the characters are on their keyboard. By the end of this tutorial, we will have a program that you will be able to quiz yourself repeatedly with as well as keep track of your score. For this demonstration I'll be using the Korean alphabet, Hangul. But, you can use any language you like as long as it has a keyboard layout for a standard WASD keyboard.

Supplies

-A functioning computer with Python 3 or a later version installed

-An basic understanding of Python and its functions (dictionaries, for loops, while loops and if statements)

-A picture of a keyboard layout for the language you are trying to learn

Step 1: Basic Structure

Make a new Python file and save it. Start by importing random. Now we can define our function, which I will call 'typing'. Keep in mind, that any of these variable names can be changed to whatever you prefer. Within our function, create two empty dictionaries: alphabet and incorrect. Then create a correct variable and assign it to 0.

Step 2: Building and Randomizing the Dictionary

The alphabet dictionary is going to be where all the correlating keys and answers will be held. Use your picture of the layout you want to learn as reference, and fill the dictionary with the non-English character being the key, and the English character being the value for each entry. For any characters that need shift to be used, simply enter the capitalized English character. Next, to randomize the dictionary we will want to make a keys variable that makes a list out of the keys() of the dictionary. Finally, we can use random.shuffle to mix up the key list.

Step 3: Creating the for and While Loops

First create a for loop that goes through the list of keys you made. Beneath that, create a variable called attempts and assign it to 3 (or however many tries you want to allow per question). Then, create a while True loop, and make your user input beneath that, assigning it to a variable called value. Value should should include the key we're iterating plus a string that asks the user for the answer in English.

Step 4: Creating Our While Loop Conditions

We will have 4 main conditions for the while loop: if the user is correct, if they want to skip (by entering a blank space), if the input is not a single letter, or if their answer was incorrect. If their input is equal to alphabet[key], print 'Correct',add 1 to the correct variable then break. If their input is nothing, we will print 'Skipped' , add their answer to the incorrect dictionary then break. Finally, if their input is not an alphanumeric character, or the length of the input is greater than 1, we tell them their input is invalid.

Step 5: Dealing With Incorrect Answers

Within our else statement at the end, we are to first be checking how many attempts the user has. If the user had only 1 attempt left, then we add the answer to the incorrect dictionary, print out the correct answer, then break. For the remaining else statement (if they still have attempts left), subtract 1 from attempts, tell the user to try again, and print out how many attempts are left.

Step 6: Seeing the Results

Hard part's over! Now, we just need to add a couple print statements to see our results. First, print that the user got correct out of length of the alphabet. To introduce the next part, print 'You got the following wrong:'. Then, use a for loop to iterate through the incorrect dictionary. Then, print each key followed by the value. Be sure to call your function at the end of the file by typing it's name unindented follower by a pair of parenthesis. And with that, our file is complete!

Step 7: Testing Your Program

Press f5 to run your program. Be sure to check all of your conditions, including correct answer, incorrect answer, skip, and invalid input. The attached photo shows what an example test run might look like.

Step 8: Concluding Thoughts

If you've made it this far, great work! You can now endlessly quiz yourself until you are a touch typist in your desired language. Python contains infinite possibilities, so don't be afraid to tinker around to add or change features of the program. Thank you for reading!

Work From Home Speed Challenge

Participated in the
Work From Home Speed Challenge