flashcard problem in python

I need an algorithm that needs to be translated into python and explain how i did it.