Teaching kids to program
Building a cryptoquote game with Python, Streamlit and Heroku
There are two kinds of literacy which every kid should acquire in school:
- Financial Litercacy
- Programming Literacy
While little is done about financial literacy even in the developed world besides some private initivatives (like my friend Mara’s books for children here or here), programming has gained more prominence in Europe’s schooling schedules for whatever reason. Naturally, as a parent you want to take every opportunity to support interest in creative digitalism.
My daughter is using the online LateX editor Overleaf to write academic papers and I’m always baffled how so called digital natives can waste hours and days formatting their work on MS Office products when free solutions are available and much more efficient.
During the pandemic, our locked-in family members spread across the world have gathered occasionally for a game of “cryptoquote” — an addition to Alabama’s capital newspaper. This takes a more or less famous quote and scrambles around the letters. The result is a a random shifting cypher that can be put together like a sudoku puzzle, taking orientation from the most used letters like “e” and “i” as well as their placement in the quote.
To provide some extra material for the game, I’ve put together the following finger exercise.
The pseudo-code looks like this:
- Get the quote to be scrambled from the user
- Remove some unwanted punctuation.
- Create a copy of the quote
- Randomly scramble the index of the set of letters used.
- Loop through the words of the original quote and look up the encrypted letter from the scrambled index.
- Print out the encrypted quote
- Play the game and see who get’s it first.
Taking advantage of the fast-prototyping qualities of Python, the actual code for this could be written like this:
It is written as a standalone module, meaning it can be run separately from the command line with
python cryptoquote.py “One very impressive quote”
or imported into the GUI. For the GUI I’ve first tried PySimpleGUIWeb but didn’t like the look and feel. So, despite it being total overkill for a text-in-text-out interface, this project ended up with the shiny Streamlit GUI, a really amazing project. With a couple of lines of easy code, this produces a highly polished web interface that can be run on example on Heroku:
Play a round for yourself here. Remember, this might take 20secs to fire up as it runs on the free version of Heroku.
If you want to get the GUI running on your local machine, you can use the following code:
On your local machine, this will run with
streamlit run st_app.py
Thanks for reading and have fun playing!
Bjoern Holste — Technology Institute