Python Flashcards Game

This is part of my poker math game as there are topics from he book that work well for the format of flashcards. This is really simple program that demonstrates how to do several interesting things in python.

The first couple functions show a simple way to wait for the user to input some data. The reason I’m assigning the output to __ is to show that I’m not going to use that data. The double underscore variable is a standard way of expressing that in python.

At the beginning of the main (line 16) I call clear to clear out the terminal window and give me a fresh looking space. This shows the simple way to call system commands from python.

On line 20 we use the with ... as syntax to open the file. This is a special kind of statement for resources like files that need to be cleaned up when you finish using them. The advantage of with is that when execution goes out of scope it will clean up the file which will close it. That means that if any of the code inside throws an exception the file will be closed.

Line 21 uses the pythonic line reading syntax to read from the file. The variable cards refers to the file and for line in file will loop through a file a line at a time in python.

Line 24 is the next interesting syntax piece. To understand it we need to break it down. The first thing that split is separating the line into a list of strings, splitting anytime it sees a comma. The second thing is the list compression. List compression is a syntax that efficiently does something on each item in a list and the syntax is [action for item in list]. strip() is a function that removes whitespace and the beginning and end of a line and I’m using it specifically to clean up any extra whitespace in the csv file lines.

So there you have it, a simple flashcards python app you can use for studying. To follow the advancements in my python game go checkout my github repo and let me know what you think.


  1. secured
    April 20, 2017

    What’s up it’s me, I am also visiting this website regularly, this site is truly nice and the visitors are genuinely sharing fastidious thoughts.

  2. money investment advice
    April 20, 2017

    I enjoy, cause I found just what I was having a look for. You’ve ended my four day long hunt! God Bless you man. Have a great day. Bye

  3. continuing education
    April 20, 2017

    Howdy! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the superb work!


Leave a Reply

Your email address will not be published. Required fields are marked *