Python Project: Learning German - Adding Terms, Guessing Gender, and Translation Game
Hello everyone! As many of you who have been following my father (@remlaps) may know, we have spent the last 6 months learning German using the app Duolingo. We still have much to learn, but one day we were talking about it and realized that there wasn't really a way to practice solely guessing the gender of each of the nouns in the app, or a way to simply focus on practicing vocabulary. I knew a bit about python (not a tremendous amount), and decided it might be fun to try to expand my knowledge of both German and Python by trying to make a program that will help with German language practice.
Here is a link to the github for the project. I only uploaded the code. I did not upload any of the files. I am hoping that I wrote the code correctly so that it will make files if it doesn't have them. Please let me know if the code does not work, and I will do what I can to fix it.
For anyone who knows python, please feel free to tell me if something I did was sloppy, or if there is a better way to do something.
Pixabay.com: Public Domain
The first thing I realized when trying to create this project was that I did not want to sit there formatting a list of the words I know myself; I knew that I wanted to store the words in an organized way, and I wanted to write a program that would go through all the steps for me. So the first file I made was the Add_Term.py file. I realized that the easiest way to store this information would probably be to create different files for the German words, and a different file for the English translations, and to make different files for der, das, and die. Later on, I made different files for other types of words (i.e. Adjectives, Verbs, Prepositions, etc. . .) I'm not sure if this is the most effective way to store the words or not. If you know of a better way, please feel free to let me know.
While the code I have now is fairly clean, it was not always that way. Originally, I copy and pasted the code and changed the word type (so from der to das to die). I then had one typo somewhere in the code, and painstakingly read through it all to figure out why it wasn't working properly. My father (@remlaps) then pointed out to me that I can define functions and simply use variables to change the files. So I rewrote all of the code with that in mind. The good news was that the later parts of the project became so much easier because of this.
I immediately made it so that it would add words to their respective files in an order where the two could be connected later on (When I download them from the file). What I later did was made it so the program would open the file and read it first to make sure the word was not already in the file. Here's an example:
As you can see, if the word is already in the file, the program will say (in German) "This word has already been added!"
Originally, I made it so that words had to be added in a sequence:
First input type of word (der, das, or die) click enter
Second input German word click enter
Third input English translation click enter
I later realized I could have the computer take all three in an input and separate them. So now an input can be:
First input type of word German word English translation click enter
Here's an example:
The word train station really posed a problem for me at first because the German is one word, but the English is two. I realized though that I could still make the program read it as one translation. I could now have one German word that is 42 English words, and it would still store properly.
Similarly, I later made it so the program could add phrases of multiple words (such as "Guten Abend" - "Good evening"). However in that case, make sure not to input the terms in the same line or it will read everything after the third word as English (Even if the German is multiple words).
The next thing I worked on was making a game to guess the Gender of the nouns. I wanted this game to make it more likely for words that have been previously incorrect to appear. To do this, I made respective files for incorrect der, das, and die words. I made it so that when the program was making the list of words (using the stored terms) it also added the words in the incorrect file to the list. This means that the words that are incorrect show up multiple times in the list of possible words, and have a higher chance of being selected the more the person gets them wrong. I made it so once the gender is correctly guessed, one instance of the word in the file will be erased. Similarly, I made the file add words which had been incorrectly answered to the list.
I later made it so that streaks, correct count, and incorrect count would be tracked. To end the game, the individual must type "verlassen", "quit", "v", or "q". I made it so that at the end of the game, the streak and count will be checked against the high score, and the high score will be changed if either is higher.
Here's an example of the Gender Guess:
And here is what the end of the game looks like:
In terms of the code, the word translation is very similar to the gender guess. The only difference being in the lists of possible words that are used, and checking the answer. The answer must come from a file instead of arbitrarily being der, das, or die. Similarly, it can be translating from German to English, or English to German. I did have some problems at first, but it now works fairly well. Here's an example of that:
One thing I have to learn, is how to make it so that if a verb is not typed with "to. . ." it is still counted as correct, or if a noun is typed with "the. . ." it is still counted as correct. The end of the game is very similar to the Gender Guess:
What do I hope to change?
I hope to make a game to focus on conjugating the verbs. I still need to figure out how to store the irregular conjugations though (if anyone has any ideas, please feel free to share them). I also hope to find ways to make it more entertaining, and maybe someday figure out a way to incorporate blockchain. For now, it is a small project which I have been working on.
Thank you for reading this! I hope this program is helpful if anyone out there is trying to learn German! Please feel free to leave feedback, and have an amazing day!