2. Programming Principles
Four lectures a week for 14 weeks
Class: 12h30, Tuesday
12h30, Wednesday
09h30-11h25, Friday
Practical session: Thursday 16h30
Test: 2 minimum, assignment, presentation, Quiz
3. Ms. Ntinda M.N
Assistance: Mathe and Paulus
Light talks (5 min max)
Install:
Windows OS
Python 3….
gedit
Day1
4. Is to teach you to think like a
computer Scientist
This way of thinking combines
some of the best features of
mathematics, engineering and
natural science
Goal
5. Like Mathematicians, Computer scientists use formal
languages to denote ideas(Specifically computation)
Like Engineers, they design things, assembling
components into systems and evaluating tradeoffs
among alternatives
Like Scientists, they observe the behavior of complex
systems, form hypotheses and test predictions
Goal
6. Natural Language Formal Language
Full of ambiguity which people deal with
by using contextual clues and other
information
Designed to be nearly or completely
unambiguous, which means that any
statement has exactly one meaning,
regardless of context
In order to make up for ambiguity and
reduce misunderstanding, natural
languages employ lots of redundancy
Less redundant and more concise
Literalness are full of idiom and
metaphor
Mean exactly what they say
Natural language vs Formal
Language
7. The single most important skill for a computer
Scientist is problem solving
Goal
8. The ability to formulate problems, think creatively
about solutions and express a solution clearly and
accurately.
The process of learning to program is an excellent
opportunity to practice problem solving skills
Problem Solving means:
9. Is an artificial language used to write instructions that can
be translated into machine language and then executed by
a computer. Examples:
Python
Visual basics
Java
C#
C++
Pearl
What is a programming Language
10. The programming Language you will be learning in
this course is Python
Python is an example of a high level programming
language.
Other High level programming languages:
C,C++,Perl and Java
Programming Language
11. There are also low-level programming languages,
sometimes referred to as “machine Languages” or
“Assembly languages”
Example of low level programming Languages:
Machine language and Assembly language
Programming Languages
13. High level enable a programmer to
write programs that are more or less independent of
a particular type of computer.
Such languages are considered high-level because
they are closer to human languages and further
from machine languages.
In contrast, assembly languages are considered low-
level because they are very close to machine
languages.
Define: High level language, Low
level languages
14. Computers can only execute programs written in low
level languages.
Programs written in high level language have to be
processed before they can run.
This extra processing takes some time, which is a
small disadvantage of high level languages.
15. A related meaning "to execute" refers to the specific
action of a user starting (or launching or invoking) a
program, as in "Please run the ... application.“
“RUN”
16. High level Low level
It is much easier to program Difficult to program
Takes less time to write, shorter
and easier to read and more likely
to be correct
Take longer to write and not easy
to read
Portable(they can run on
different kinds of computers with
or no modifications)
Low level programs can run on
only one kind of computer and
have to be rewritten to run on
another
High level vs low level languages
17. Two kinds of programs process high-level languages
into low-level languages:
Interpreters and Compilers
High-level program languages
18. A compiler reads the program and translate it
completely before the program starts running.
Compiler
Compiler Object code
Executor Output
19. In this case, a high-level language is called, a source
code and the translated program is called the object
code or the executable.
Once a program is compiled, you can execute it
repeatedly without further translation
Compiler continue……
20. An interpreter reads a high-level program and
executes it, meaning that it does what the program
says, it processes the program a little at a time,
alternatively reading times and performing
computations
Interpreter
OutputInterpreter
Source
Code
21. Python is considered to be an interpreted language
because python programs are executed by an
interpreter
Interpreter
22. A program is a sequence of instructions that specifies
how to perform a computation.
The computation might be something mathematical
such as solving a system of equations or finding the
roots of a polynomial, but it can also be a symbolic
computation such as searching and replacing text in a
document
What Is a program?
23. Input: get data from the keyboard, a file or some
other device
Output: Display data on the screen or send data to a
file or other device
Math: perform basic mathematical operations like
addition and multiplication
Conditional execution:
Check for certain condition and execute the appropriate
sequence of statement.
Perform some repeatedly, usually with some variation
Every program you have ever used is
made up of the following
instructions:
24. Programming is the process of breaking a large
complex task into smaller and smaller subtasks until
the subtasks are simple enough to be performed with
one of these basic instructions.
What is programming
25. Programming is a complex process, and because it is
done by human beings, it often leads to errors.
Python can only execute a program if the program is
syntactically correct otherwise the process fails and
returns an error message.
Three kinds of errors
Runtime errors
Syntax errors
Semantic errors
What is debugging
26. Syntax refers to the structure of a program and the
rules about that structure.
Example:
In English, a sentence must begin with a capital letter
and end with a period.
In English, you can be forgiven when you have a
grammatical error.
Python is not forgiving
Syntax errors
27. If there is a single error anywhere in your program,
python will print an error message and quit, and you
will not be able to run your program
Learn your Syntax
Beginners spend more time tracking errors, make use
of Google……with experience, you will make few
errors and track them down easier
Syntax errors cont……
28. Runtime errors does not appear until you run the
program.
These errors are also called exceptions because they
usually indicate that something exceptional(and bad)
has happened.
Runtime errors are rare in the simple programs, you
will see in the first few examples you might not
encounter one
Runtime errors
29. Occurs when the program run successfully, in the
sense that the computer will not generate any error
messages but it will not do the right thing.
The program will do something else.
Semantic errors
30. Example:
We want to add 5+10 = 15 instead we add 3+10 = 13.
Identifying semantic errors can be tricky because it
requires you to work backward by looking at the
output of the program and trying to figure out what it
is doing
Semantic errors cont….
31. Know how to debug
For some people, debugging and programming is the
same thing.
Programming is the process of gradually debugging a
program until it does what you want.
Debugging
32. Command-line mode and script mode
In command-line mode, you type python programs
and the interpreter prints the results
In a script mode, you can write a program in a file and
use the interpreter to execute the contents of the
file. Such a file is called a script.
Use a text editor to crate a file.
As with MsWord file .doc,,,,,,,,python files end with
.py
There are two ways to use an
interpreter:
33. Python is a very popular programming language that
can be used for creating websites, games, scientific
software, graphics
Python originated in the late 1980s and its main goal
is to be readable by human beings (not only
machines!).
Python
34. https://www.python.org/downloads/
make sure you scroll down and choose the "Add
python.exe to the Path" option, as
shown here:
Type python in cmd to
Confirm it was
successfully installed
Download Python for Windows
from the website
35. Gedit is an open-source, free editor, available for all
operating systems.
http://ftp.gnome.org/pub/GNOME/binaries/win32/gedi
t/2.30/
Why are we installing a code editor?
Code needs to be plain text
Problem with programs like Word and Textedit is that
they don't actually produce plain text, they produce rich
text (with fonts and formatting)
Code editors provide helpful features, like highlighting
code with colour according to its meaning, or
Code editor: gedit
36. command line or command-line interface
is a text-based application for viewing, handling, and
manipulating files on your computer.
Other names for the command line are:
cmd,CLI, prompt, console or terminal.
Open the command-line interface
Windows
Go to Start menu → All Programs → Accessories →
Command Prompt.
Prompt
On Windows, it's a > sign, like this: command-line >
Introduction to the command-line
interface
37. Current directory (know where we are)
> cd
C:Usersnntinda.UNAM.000
List files and directories (what's in it?)
> dir
Directory of C:Usersnntinda.UNAM.000
05/06/2015 07:28 PM <DIR> Applications
05/06/2015 07:28 PM <DIR> Desktop
05/06/2015 07:28 PM <DIR> Downloads
05/06/2015 07:28 PM <DIR> Music ...
Basics: Each operating system has a slightly
different set of commands for the command
line
38. Change current directory (let's go to Desktop directory)
> cd Desktop
PRO tip:
if you type cd D and then hit tab on your keyboard,
the command line will automatically autofill the
rest of the name so you can navigate faster. If
there is more than one folder starting with "D", hit
the tab button twice to get a list of options.
Basics: Each operating system has a slightly
different set of commands for the command
line
39. Create directory (folder) title: helloWorld
> mkdir helloWorld
PRO tip:
If you don't want to type the same commands over and
over, try pressing the up arrow and down arrow on your
keyboard to cycle through recently used commands.
Basics: Each operating system has a slightly
different set of commands for the command
line
40. • Create a folder on your desktop called firstYearDiploma
• In your newly created firstYearDiploma directory create a
directory called name,20150999(student number).
Exercise