Computer Programming: Basic Elements of Python Programs
Computer Programming: Basic Elements of Python Programs
PROGRAMMING Programs
GETTING STARTED
WITH PYTHON
WOODGROVE 2
BANK
WHAT IS COMPUTER PROGRAMMING
Programming or Computer programming is a way of giving
an instruction to a computer to perform a specific task. In
programming world, it often refer to as coding.
WOODGROVE 3
BANK
A computer system is made of electronic devices which operates from 0v to 5v. In
computer design these voltages are divided into two states, which is the High and
Low. High corresponds to ranges close to 5v while the Low corresponds to the
voltages near 0v or ground. These states are converted into a number system called
binary. Thus the computer/machine language are a series of binary digits (Bits) of 1
and 0.
WOODGROVE 4
BANK
THE LANGUAGE OF COMPUTERS
WOODGROVE 5
BANK
COMPARISON
Low level languages and High Level Languages
• It has no abstraction and the programming • It has a high-level of abstraction and focus
rely closely to the computer architecture. To mainly on the programming logic rather than
create a program using a low level language, the underlying hardware architecture. It is
the programmer must understand the more user friendly and generally independent
architecture of the computer system such as from the computer hardware.
the number of registers, the size of memory,
register and cache, how the device are
connected to each other, how many
instruction the machine is capable and what
are these instructions.
• Low level program codes are divided into two
parts. the opcode and the operand.
WOODGROVE 6
BANK
TRANSLA
TORS
WOODGROVE 7
BANK
TRANSLATORS
• programming language is similar to a natural
language, the machine needs a translator for it
to understand.
• translator’s task is to translate the source
code into computer codes which is basically a
set of binary numbers.
INTERPRETERS
COMPILERS
ASSEMBLER
WOODGROVE 8
BANK
TRANSLATORS INTERPRETERS
WOODGROVE 10
BANK
TRANSLATORS ASSEMBLER
Assembly language (or assembler language), also abbreviated asm, is any low-level
programming language in which the instructions in the language and the computer
code instructions of the machine correlates quite strongly.
WOODGROVE 11
BANK
FACTS ABOUT PYTHON
• Development started in the 1980’s by
Guido van Rossum.
• Only became popular in the last
decade or so.
• Python 2.x currently dominates, but
Python 3.x is the future of Python.
• Interpreted, very-high-level
programming language.
• Supports a multitude of programming
paradigms.
• OOP, functional, procedural, logic,
structured, etc.
• General purpose.
• Very comprehensive standard library
includes numeric modules, crypto
services, OS interfaces, networking
modules, GUI support, development
tools, etc.
WOODGROVE 12
BANK
INTERESTING FACTS ABOUT PYTHON
• Python was a hobby project
In December 1989, Python‟s creator Guido
Van Rossum was looking for a hobby project
to keep him occupied in the week around
Christmas. He had been thinking of writing a
new scripting language that‟d be a
descendant of ABC and also appeal to
Unix/C hackers. He chose to call it Python.
WOODGROVE 13
BANK
FACTS ABOUT PYTHON
WOODGROVE 14
BANK
PYTHON Python syntax and
codings
PROGRAMMING
WOODGROVE 15
BANK
WOODGROVE
BANK
In the following example, the parameter values passed to the print function are all
technically called literals
Programming is fun!
>>> x = 2.3
>>> print(x)
2.3
WOODGROVE
BANK
A simple way to view the effect of an assignment is to assume that when a variable
changes, its old value is replaced
>>> x = 2
before
>>> print(x) X=2
2
>>> x = 2.3
after
Python assignment statements are actually slightly different
>>> print(x) X = 2.3 from the “variable as a box” model
2.3
In Python, values may end up anywhere in memory, and
variables are used to refer to them
WOODGROVE
BANK
Interestingly, as a Python programmer you do not have to worry about computer memory
getting filled up with old values when new values are assigned to variables
So far, we have been using values specified by programmers and printed or assigned to variables
>>> name
'Mohammad Hammoud'
>>>
>>> number
„3‟
How can we force an input number to be stored as a number and not as a string?
We can use the built-in eval function, which can be “wrapped around” the
input function
WOODGROVE
BANK
>>> number
5
Besides, we can convert the string output of the input function into an integer
or a float using the built-in int and float functions
>>> number
3
WOODGROVE
BANK
Besides, we can convert the string output of the input function into an integer
or a float using the built-in int and float functions
>>> number
3.7
WOODGROVE
BANK
This form of assignment might seem strange at first, but it can prove
remarkably useful (e.g., for swapping values)
>>> x, y = 2, 3
>>> x
2
>>> y
3
WOODGROVE
BANK
Suppose you have two variables x and y, and you want to swap their values
(i.e., you want the value stored in x to be in y and vice versa)
>>> x = 2
>>> y = 3
>>> x = y
>>> y = x
>>> x
3
>>> y
2
WOODGROVE
BANK
>>> print(x)
10
>>> print(X)
5.7
• Programs are composed of statements that are built from identifiers and expressions
• A literal is a representation of a specific value (e.g., 3 is a literal representing the number three)
• A variable is an identifier that stores a value, which can change (hence, the name variable)
WOODGROVE
BANK
In Python, assignment of a value to a variable is done using the equal sign (i.e., =)
Using assignments, programs can get inputs from users and manipulate them internally
Python allows simultaneous assignments, which are useful for swapping values of
variables
THANK YOU!
+63 966 926 6290
SIR TATTS
cp.talusan@gmail.com