How to Write a Python Program

Joseph Mellor
16 min readMar 9

Knowing what the tools do is necessary to write a program, but you also need to know how to structure a program.

Image made by me using the python logo, cool-retro-term, vim, the onedark color scheme, and GIMP.

If you’ve kept up with this series, you should have python installed, you should understand the core operators of python, you should know how to control the flow of a program, you should know how to handle files, and you should know how to get other libraries into your program. In this article, we’re going to use everything we learned up to this point to write a program to test the Zipf Hypothesis.

While there’s plenty of articles about data analysis, I want to focus on how we can do anything by breaking a major task into smaller tasks.

Breaking a Big Task into Smaller Tasks

Right now, we have a big task: test the Zipf Hypothesis on some data. Unless you know the exact code to write for this task, you’re going to have to break this task into smaller tasks. To figure out how to break these tasks apart, I ask myself the following questions:

Outputs

  • What information do I want?
  • How should I format the information I want?
  • What do I need to know to get this information?

Inputs

  • What information do I have?
  • Can I add more information or change the information I have?
  • How is the information I have formatted?
  • What can I do with this information?

Implementation

  • How can I get this information where it needs to be (a function, object, data structure, etc.)?
  • Is there code I can write or use to connect my outputs to my inputs? If not, how can I split this task into smaller tasks with their own inputs and outputs?

I tend to ask these questions in this order, as knowing where I want to end up helps me make sure I’m going in the right direction and knowing what I have helps me figure out my next step. Once I know where I am and where I’m going, I can then figure out what I need to do to get where I want to be.

Joseph Mellor

BS in Physics, Math, and CS with a minor in High-Performance Computing. You can find all my articles at https://josephmellor.xyz/articles/.