Teaching kids to program

Building a cryptoquote game with Python, Streamlit and Heroku

Bjoern Holste
3 min readDec 1, 2020
Thistle flower in front of my neighbour’s house

There are two kinds of literacy which every kid should acquire in school:

  1. Financial Litercacy
  2. 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:

  1. Get the quote to be scrambled from the user
  2. Remove some unwanted punctuation.
  3. Create a copy of the quote
  4. Randomly scramble the index of the set of letters used.
  5. Loop through the words of the original quote and look up the encrypted letter from the scrambled index.
  6. Print out the encrypted quote
  7. 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:

Code for the simple random scrambling over the index

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:

cryptoquote.herokuapp.com
Screenshot from the GUI running on Heroku and powered by Streamlit.

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:

Some lines of code to create the entire web GUI with Streamlit!

On your local machine, this will run with

streamlit run st_app.py

Thanks for reading and have fun playing!

Bjoern Holste — Technology Institute

--

--