Chapter 3
Chapter 3
1
ITBS103
❑ Objectives
▪ Learn the essential fundamentals of computer
programming,
▪ Learn Python
▪ Learn Python programming environment.
2
ITBS103
2
Section 1 – Introduction to Programming
Natural languages vs programming languages
❑ A language is a means (and a tool) for expressing and recording thoughts.
❑ Computers have their own language, too, called machine language, which is
very rudimentary.
❑ A computer, even the most technically sophisticated, is devoid of even a trace
of intelligence. You could say that it is like a well-trained dog - it responds only
to a predetermined set of known commands.
❑ The commands it recognizes are very simple. We can imagine that the
computer responds to orders like "take that number, divide by another and
save the result".
3
ITBS103
4
ITBS103
4
Machine language vs. high-level language?
❑ The IL is, in fact, the alphabet of a machine language. This is the simplest and most
primary set of symbols we can use to give commands to a computer. It's the computer's
mother tongue.
❑ Unfortunately, this mother tongue is a far cry from a human mother tongue. We both (
computers and humans) need something else, a common language for computers and
humans, or a bridge between the two different worlds.
❑ We need a language in which humans can write their programs and a language that
computers may use to execute the programs, one that is far more complex than machine
language and yet far simpler than natural language.
5
ITBS103
❑ Such languages are often called high-level programming languages. They are at
least somewhat similar to natural ones in that they use symbols, words and
conventions readable to humans. These languages enable humans to express
commands to computers that are much more complex than those offered by ILs.
❑ A program written in a high-level programming language is called a source code
(in contrast to the machine code executed by computers). Similarly, the file
containing the source code is called the source file.
6
ITBS103
6
Section 1 – Introduction to Programming
❑ Let's assume that you've successfully written a program. How do we persuade the computer to execute it? You have to
render your program into machine language. Luckily, the translation can be done by a computer itself, making the whole
process fast and efficient.
7
ITBS103
8
ITBS103
8
Section 1 – Introduction to Programming
❑ The interpreter will inform you where the error is located and what caused it. However, these messages may be
misleading, as the interpreter isn't able to follow your exact intentions, and may detect errors at some distance from
their real causes.
❑ If the line looks good, the interpreter tries to execute it (note: each line is usually executed separately)
❑ You may ask now: which is better? The "compiling" model or the "interpreting" model? There is no obvious answer. If
there had been, one of these models would have ceased to exist a long time ago. Both of them have their advantages
and their disadvantages.
9
ITBS103
10
ITBS103
10
Section 2 – Introduction to Python
▪ Python was created by Guido van Rossum, born in 1956 in Haarlem, the Netherlands. Of course, Guido van
Rossum did not develop and evolve all the Python components himself. The speed with which Python has spread
around the world is a result of the continuous work of thousands (very often anonymous) programmers, testers,
users (many of them aren't IT specialists) and enthusiasts.
11
ITBS103
11
❑ Python goals
In 1999, Guido van Rossum defined his goals for Python:
▪ an easy and intuitive language just as powerful as those of the major competitors;
▪ open source, so anyone can contribute to its development;
▪ code that is as understandable as plain English;
▪ suitable for everyday tasks, allowing for short development times.
❑ About 20 years later, it is clear that all these intentions have been fulfilled. Some sources say
that Python is the most popular programming language in the world, while others claim it's
the second or the third.
❑ Either way, it still occupies a high rank in the top ten of the PYPL PopularitY of Programming
Language and the TIOBE Programming Community Index.
❑ Python isn't a young language anymore. It is mature and trustworthy. It's not a one-hit
wonder. It's a bright star in the programming firmament, and time spent learning Python is a
very good investment.
12
ITBS103
12
Section 2 – Introduction to Python
❑ Why Python?
❑ it's easy to learn – the time needed to learn Python is shorter than for many other
languages; this means that it's possible to start the actual programming faster;
❑ it's easy to teach – the teaching workload is smaller than that needed by other
languages; this means that the teacher can put more emphasis on general (language-
independent) programming techniques, not wasting energy on exotic tricks, strange
exceptions and incomprehensible rules;
❑ it's easy to use for writing new software – it's often possible to write code faster when
using Python;
❑ it's easy to understand - it's also often easier to understand someone else's code faster
if it is written in Python;
❑ it's easy to obtain, install and deploy – Python is free, open and multiplatform; not all
languages can boast that.
13
ITBS103
13
❑ Python rivals?
❑ Python has two direct competitors, with comparable properties and predispositions. These are:
❑ The former is more traditional and more conservative than Python, and resembles some of the old languages
derived from the classic C programming language.
❑ In contrast, the latter is more innovative and more full of fresh ideas than Python. Python itself lies somewhere
between these two creations.
❑ The Internet is full of forums with infinite discussions on the superiority of one of these three over the others,
should you wish to learn more about each of them.
14
ITBS103
14
Section 2 – Introduction to Python
15
ITBS103
15
❑ low-level programming (sometimes called "close to metal" programming): if you want to implement an
extremely effective driver or graphical engine, you wouldn't use Python;
❑ applications for mobile devices: although this territory is still waiting to be conquered by Python, it will most
likely happen someday..
16
ITBS103
16
Section 2 – Introduction to Python
▪ Python 2 is an older version of the original Python. Its development has since been
intentionally stalled, although that doesn't mean that there are no updates to it. On
the contrary, the updates are issued on a regular basis, but they are not intended to
modify the language in any significant way. They rather fix any freshly discovered
bugs and security holes. Python 2's development path has reached a dead end
already, but Python 2 itself is still very much alive.
▪ Python 3 is the newer (or to be more precise, the current) version of the language.
It's going through its own evolutionary path, creating its own standards and habits.
17
ITBS103
17
18
ITBS103
18
Section 3 – Downloading and Installing Python
❑ Top Python IDEs & Code Editors: Download for Free & Paid
19
ITBS103
19
20
ITBS103
20