Python
Gillian Aprille Sarmiento, CpE
Resources: Introduction to programming w/ python, Harris Wang
Phases of Software System Development
Algorithm design and representation are essential
when programming for computers to solve a problem
or complete a task, but it is only part of software
system development. Developing a software system to
satisfy the requirements of a client requires several
phases.
1. UNDERSTAND THE PROJECT
2. ANALYZE THE REQUIREMENTS TO IDENTIFY COMPUTER-SOLVABLE
PROBLEMS AND TASKS
3. DESIGN THE SYSTEM
4. IMPLEMENT THE SYSTEM
5. TEST THE SYSTEM
6. MAINTAIN THE SYSTEM
UNDERSTAND THE PROJECT
When developing a software system at the
request of a client or customer, the first thing to
do is to understand what the client really needs
so that you can get a clear definition of the
problems to be solved and the tasks to be
completed by the software system.
ANALYZE THE REQUIREMENTS TO IDENTIFY
COMPUTER-SOLVABLE PROBLEMS AND TASKS
Requirement analysis will turn client’s
requirements into problems and tasks suitable for
computers to solve or complete. This often
involves a strategy called divide and conquer,
which means dividing big problems or tasks into
smaller ones to solve.
DESIGN THE SYSTEM
The next important thing at the system design phase is
to design algorithms for each of the identified
problems and tasks.
Your knowledge and skill in system design, problem
solving, and mathematical and logical thinking play
important roles at this phase.
IMPLEMENT THE SYSTEM
Implementation involves programming to
solve the problems and complete the tasks
identified at phase 2, based on the structure
of the system and algorithms designed at
phase 3, as well as integration of all the
subsystems and modules to make them work
together.
TEST THE SYSTEM
The system implemented at phase 4 may not
correctly reflect what the client wants and may
have errors and bugs. A thorough test is needed
to find the bugs and close up the gaps between
what has been implemented and what the client
really wants.
MAINTAIN THE SYSTEM
Maintaining the system is often an even bigger task
after the release and delivery of the software because
there is no guarantee that all bugs were found during
the test, no guarantee that the implementation
genuinely reflects the needs of the client, and no
guarantee that the client will not come up with a
“better” idea or requirements after the fact.
Programming for computers is writing instructions for computers to
execute.
Interactive programming is programming in an environment in which
you can interact with a computer, the interpreter of the programming
language, more precisely, instruction by instruction.
The opposite of interactive programming is batch programming, in
which you will need to write a complete program and then feed the
entire program to a language engine such as an interpreter, language
runtime, or virtual machine in order to execute it.
What is Python?
Python is a popular programming language. It was
created by Guido van Rossum, and released in 1991.
It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
What can Python do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and
modify files.
• Python can be used to handle big data and perform complex
mathematics.
• Python can be used for rapid prototyping, or for production-
ready software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs
with fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code
can be executed as soon as it is written. This means that
prototyping can be very quick.
• Python can be treated in a procedural way, an object-
oriented way or a functional way.
Python Syntax compared to other
programming languages
• Python was designed for readability, and has some similarities
to the English language with influence from mathematics.
• Python uses new lines to complete a command, as opposed to
other programming languages which often use semicolons or
parentheses.
• Python relies on indentation, using whitespace, to define
scope; such as the scope of loops, functions and classes.
Other programming languages often use curly-brackets for
this purpose.
File type
Saved as .py
Whenever you are done in the python command line, you can
simply type the following to quit the python command line
interface:
exit()
Python Indentation
Indentation refers to the spaces at the beginning of a
code line.
Where in other programming languages the indentation
in code is for readability only, the indentation in Python
is very important.
Python uses indentation to indicate a block of code.
Note: Case Sensitive
For eg:
if 3 > 1:
print(“three is greater than one")
Syntax error:
if 3 > 1:
print(“three is greater than one")
Operators and expressions in Python
Operators:
+ operator for addition
- operator for subtraction
* operator for multiplication
/ operator for division
% operator for modulus
** operator for exponentiation
// operator for floor division
Comments
Python has commenting capability for the purpose of in-
code documentation.
Comments start with a #, and Python will render the rest
of the line as a comment:
Eg: #This is a comment.
Since Python will ignore string literals that are not
assigned to a variable, you can add a multiline string
(triple quotes) in your code, and place your comment
inside it:
"""
1
2
3
"""
Python Variables
Variables are containers for storing data values.
In Python, variables are created when you assign a value
to it:
x = 5
y = 1
Variables - Casting
If you want to specify the data type of a variable, this
can be done with casting.
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Get the Type
You can get the data type of a variable with
the type() function.
x = 5
y = "John"
print(type(x))
print(type(y))
Single or Double Quotes?
String variables can be declared either by using single or
double quotes:
x = "John"
# is the same as
x = 'John'
Variable names are case-sensitive.
a = 4
A = “1"
#A will not overwrite a
Rules for Python variables:
• A variable name must start with a letter or the
underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE
are three different variables)
• A variable name cannot be any of the Python keywords.
Quiz # 1: Testing your knowledge
Create a simple program that will display the ff output, but you will
need three different variables each containing the three word output,
and you will the combine these three variables into one variable before
displaying the output shown: (output should be exactly as shown
below)
I AM INEVITABLE!
Quiz # v1.2: Testing your knowledge
Create a simple program that will display the ff output, but you will
need four different variables each containing string values word, and
you will the combine these four variables into one variable before
displaying the output shown: (output should be exactly as shown
below)
“We will Rock You!”