Anatomy of a computer program

Computer programs are a set of step-by-step instructions used to teach the computer how to complete a task.

Computer programs are written using a specific programming language. Nowadays, most programmers would write code using a high-level programming language such as Python, C, C#, Java, Ruby or Basic.

If we were to dissect a computer program, we would find the following elements:

  • Reserved Keywords & Built-in Functions
  • Identifiers (e.g. for variables and subroutines)
  • Values of different data types
  • Computing Operators
  • Punctuation signs
  • Comments/Annotations

Let’s investigate these elements further… Click on the sub sections below to find out more.

Reserved Keywords & Built-in Functions
The reserved keywords are defined by the language used to write your code. As opposed to a foreign language like French or Spanish, high level programming languages such as Python or Java only have a few dozen reserved keywords.

For instance, in Python 3.6 there are 33 reserved keywords and a few built-in functions such as print,input,str,int,float.

Here is a non-exhaustive selection of some of the most useful Python reserved keywords and built-in functions.

Reserved Keywords:

if elif else
while break continue
for in as
import from global
def return local
class del none
try except raise

Built-in Functions:

print input range
str int float
min max round
len chr ord
Identifiers (e.g. for variables and subroutines)
Identifiers are the name the programmers will choose when creating a variable, a constant, a function or a procedure. For instance, when storing the score of a game using the following line of code:

score = 0

score is the identifier of the variable that stores the score of the player.

Note that a programmer cannot used reserved keywords or built-in functions as identifiers in a program.

For instance in python you cannot have a variable called while as input is a reserved keyword of the language.

Note that, with Object-Oriented Programming languages, you will also use identifiers to give a name to your classes and objects.

Values of different data types
The values are the pieces of data used in a program. They can be hardcoded within the code or retrieved as input.

Each value as its own data type:

  • String values which contain a alphanumerical characters e.g. “James”, “Bond”, “007”
  • Integer values which contain whole numbers (positive or negative) such as 365 or -10
  • Float values (aka Real) which contain numbers which can have a decimal point such as: 3.14 or 9.81
  • Boolean values which are either True or False

Notice how, when using a string value in your code, you have to use “speechmarks”. This is because you do not want your computer to be confused between reserved keywords, identifiers and string values.

Computing Operators
There is a range of different operators that can be used in a computer program including:

  • The Assignment Operator =, used to assign a value to a variable or a constant e.g.
    score = 0
  • Arithmetic Operators +, , *, /, **, //, % used to perform arithmetic calculations
  • Comparison Operators <, >, <=,>=, ==, !=
  • Boolean Operators and, or, not
Punctuation signs
Each language has its own syntax and its own set of punctuation signs. In the English language the example of punctuation signs are the comma ,, the full stop., the question mark ?. And syntax in a language do matter as omitting or using the wrong punctuation sign it can alter the meaning of a message. For instance, would you go swimming in these waters, knowing that “crocodiles do not swim here”?

Programming languages have their own syntax too. Not using the correct syntax in your code will generate a syntax error. This means that your computer cannot interpret your code and hence will not run it.
In Python, the main punctuation signs are the brackets (, ), [, ], { and } the colon : and the comma ,.
Comments/Annotations
Finally, most programs will include some comments (aka annotations). These are optional and are only for the benefit of the programmers who will read and work on your code. Comments provide key explanations of what a section of code is doing. Comments will be completely ignored by the computer.

In Python, comments have to start with a # sign. e.g.

#This is a single-line comment

You can also create comments over multiple lines using a triple quote: “””. e.g.

""" 
    This is a multi-line comment.
    You can add much more information here.
    These are often used at the top of your code to specify:
         - the version number, 
         - the date the code was last updated
         - copyright information.
"""

Your Task

Your task is to identify all the different elements of the short program below, and drag them in the corresponding sections.
Anatomy of a Computer Program – Drag and DropOpen in New Window

Did you like this challenge?

Click on a star to rate it!

Average rating 4.4 / 5. Vote count: 30

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!