Python for Beginners
The important truth is that learning to program is much more difficult than learning a programming language. Wait, what? You might be asking yourself what the difference is, and if so, you’re not alone.
When one learns their first programming language, one must also learn to program–that is, not just the syntax of this new language, but why programmers use certain constructs and how and why they combine those constructs to solve problems.
It’s quite easy to explain the art of programming (and yes, it’s an art, but we’ll get to that later). Programming can be boiled down to this:
- breaking a problem down into a series of steps;
- converting each step into Python or whatever language you’re working with
See? It’s quite easy to explain. Unfortunately, programming, like many things which are easy to explain, is quite difficult to do.
What could go wrong?
Well, for one thing, the steps have to be executed in the correct order. If you break down the problem into the correct steps but don’t get the order right, your code will not work.
What else could go wrong?
You could leave out a step. This happens more often than you’d think. If I ask you how to solve a problem you have solved many times in your head, you’ll often leave out a step.
What else could go wrong?
You could mistranslate a step into the code. You got the steps right, but the code you wrote does not actually perform the step. Your steps (written in English, or pseudocode–half English and half programming language) are correct, but one of more them was improperly translated.
Your task, as a beginning programmer is as follows–DO NOT WRITE ANY CODE until you’re written down the steps. If you start coding before you know the steps, how on earth are you going to get it right? It’s sort of like monkeys typing on typewriters–eventually one of them might end up writing Shakespeare, but most of them won’t. (Not that I am comparing you to a monkey, but rather, the action of writing code without knowing what you are writing–there’s no way you’ll end up with correct code if you do that.)
Here’s an example to get us started. Suppose you want to write a program which prompts the user for a number, and your program will tell the user whether the number is odd or even. Not earthshaking, but we’re beginners here. You have to crawl before you can walk. Programming is a skill, and like any skill, there will be a time when you don’t really possess it.
OK. Let’s get started. You ask me for a number. I say “57.” You say “odd.” How did you know that? What did you do in your head to elicit the response of “odd”? Let’s write down the steps:
- Get a number from the user
- Figure out the remainder when dividing that number by 2
- If the remainder is 0, the number is even, otherwise, it’s odd
Those are the steps. Don’t write any code yet! Let’s rewrite the above in pseudocode. I typically have students write their pseudocode as comments, so let’s do that,
- # prompt user for a number
- # if remainder when dividing the number by 2 is 0 then
- # print "even"
- # else
- # print "odd"
Now, let’s convert the steps into Python.
- # prompt user for a number
- number = input('Enter a number and I will tell you odd or even: ')
- # if remainder when dividing the number by 2 is 0 then
- if number % 2 == 0:
- print('even')
- else
- print('odd')
It’s not going to work. Do you see the problem? It’s difficult to see. Let’s try it.

Kiran KumariPosted Apr 25, 2019, 11:59 PM
Thanks for sharing