Kanso Tech
Programming Logic
Computers, unlike us, do not have a natural ability to do actions, even the simplest ones, or know that
some element is missing or some action needs to be done. They need to receive the correct instructions
in order to be able to execute something, and if something is missed, we will get a diferent answer,
which can be an error or a wrong answer. In a simplified way, think of a computer as a fast calculator;
it is important to say that even to act as a calculator, it needs to get the correct instructions.
We, human beings, maybe without even noticing it, use logic as a natural thing. You maybe have already
gone through some situation where you notice that something was missing, or that you done something
wrong and just adjusted it. For those that already done a fried egg (a commom example in programming
logic classes), maybe not even consider the actions of break the egg, light the fire, or analyze which
ingredients are needed to do it. It is something that we do automatically, most of the time without
thinking. Do some initial exercise: take a piece of paper and a pen (or open a notepad on your computer)
and write the necessary steps to make a fried egg.
A possible result from this exercise would be: 1) Take the egg; 2) Put it on the pan; 3) Light the fire.
What about we analyze this sequence of actions, with some questions? Where was the egg? Do you put it on
the pan without breaking it? Where was the pan? What is its size? Did you light the fire with a match or
was the stove electric? Do you see how many variables we simply do not consider, just because our
natural way of thinking understand that some elements are basic for the action to be able to execute?
Maybe you did not think about it yet, but we are a much more complex computer than the computers.
Programmig logic is a technique in which the thoughts are chained, in a way to achieve something, which
must be done also using a logic sequence, with the execution of the necessary steps until its
conclusion. It is not logic, for example, to break the egg before the fried egg is done. Computer expect
to receive this step by step in a complete manner, or they will not be able to achieve the expected
result.
Each action to be executed is an instruction, that will tell the computer what it needs to do. To perfom
a certain activity, several instructions will be passed to the computer, so that the action will be able
to be executed, remembering that it is necessary that these instructions have a logic sequence. The set
of these instructions, with a delimited amount of steps, in order to achieve something, is known as
algorithm.
Lets think a new exercise, with an algorithm that would give us an adding calculator. We could do the
following instructions: 1) Listen to the keyboard for the first number; 2) Store the first number as
"first" variable; 3) Listen the keyboard for the second number; 4) Store the second number as "second"
variable; 5) Add the first and second numbers; 6) Store the result in "result" variable; 7) Print the
result in the screen.
This simple algorithm, which does only one of the four math operations, is a logic sequence of
instructions. We could not add both number and them read the first. In the same way, it would be not
possible to show the result, without having both numbers; we would get an error or a wrong result. But
what would be, them, the softwares? You probably already understood that they are just algorithms,
written in a specific programming language, like C, Python, and so many others.
Let's do the same operation in Python? Python is a interpreted programming language, that you can
download it from Python's Website. You can use it online, if you
prefer, without the need to install anything, like in Online
Python. I know that are probably better ways to write the following code, but it just an example
(you can copy and paste, to run and see how it works. Lines beggining with # are comments).
#1) 1) Listen to the keyboard for the first number;
#2) 2) Store the first number as "first" variable;
first = int(input("Type the first number and press ENTER:\n"))
#3) Listen the keyboard for the second number;
#4) Store the second number as "second" variable;
second = int(input("Type the second number and press ENTER:\n"))
#5) Add the first and second numbers;
#6) Store the result in "result" variable;
result = first + second
# 7) Print the result in the screen.
print(result)
That's it. Learn programming logic before the programming languages, because a programming language is
just an specific tool, that you will use to make your algorithm live. The logic thinking will even help
you structure the necessary knowledge to be succeded in cybersecurity or any other area.
Voltar