T-CPET121LA
Introduction to
Computational Thinking
(Python)
Prepared by:
Joshua T. Isaguirre
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 2
CEAT – Engineering Department
Manual Contents
INTRODUCTION TO PYTHON PROGRAMMING ................................................................................ 3
What is Java? ..................................................................................................................................... 3
PYTHON FUNDAMENTALS................................................................. Error! Bookmark not defined.
Variable Casting ................................................................................ Error! Bookmark not defined.
Global vs Local Variables................................................................................................................... 6
Deleting Variables .............................................................................................................................. 7
Keywords ............................................................................................................................................ 7
Operators .......................................................................................... Error! Bookmark not defined.
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 3
CEAT – Engineering Department
This course is all about writing the code, translating the code and testing the program. There are two
levels of programming language, the High Level and the Low Level programming language.
Low-level programming language (Machine language) – The language of a computer. It is a
sequence of 0s and 1s since digital signals are processed inside a computer. The fundamental
language of the computer’s processor.
High-level programming language – Uses English like statements.
The higher-level language code is called source code. The corresponding machine language code is
called the target code. Programmers have a variety of tools available to enhance the software
development process. Some common tools include:
Editors – An editor allows the programmer to enter the program source code and save it to
files. The syntax of a language refers to the way pieces of the language are arranged to make
well-formed sentences.
Compilers – A compiler translates the source code to target code and produce an executable
program.
Interpreters – An interpreter is like a compiler. While a compiler produces an executable
program that may run many times with no additional translation needed, an interpreter
translates source code statements into machine language each time a user runs the program.
A compiled program does not need to be recompiled to run, but an interpreted program must
be reinterpreted each time it executes. For this reason interpreted languages are often referred
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 4
CEAT – Engineering Department
to as scripting languages. The interpreter in essence reads the script, where the script is the
source code of the program. Python is an interpreted language.
Debugger – A debugger allows a programmer to more easily trace a program’s execution in
order to locate and correct errors in the program’s implementation. A developer can
simultaneously run a program and see which line in the source code is responsible for the
program’s current actions.
Profilers – A profiler collects statistics about a program’s execution allowing developers to
tune appropriate parts of the program to improve its overall performance. A profiler indicates
how many times a portion of a program is executed during a particular run, and how long that
portion takes to execute.
What is Python
Guido van Rossum created the Python programming language in the
late 1980s. In contrast to other popular languages such as C, C++, Java,
and C#, Python strives to provide a simple but powerful syntax.
Back in the 1970s, there was a popular BBC comedy tv show called Monty
Python’s Fly Circus and Van Rossum happened to be the big fan of that show.
So when Python was developed, Rossum named the project ‘Python’.
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 5
CEAT – Engineering Department
In-demand Language
None of this would matter if Python was not relatable to the industry. Python is widely used in Data
Science, Web Applications or Game Development
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 6
CEAT – Engineering Department
VARIABLES
Variable is a primary storage location that holds different numeric or alphanumeric values. It is also a
memory space allocated by a computer user for processing and storing data. In most of the
programming languages a variable is a named location used to store data in the memory. Each
variable must have a unique name called identifier.
Initiating Variables
In Python, variables do not need declaration to reserve memory space. The "variable declaration" or
"variable initialization" happens automatically when we assign a value to a variable.
START
Declarations
int A = 5
float B = 10.5
string C = "Hello"
Boolean D = True
STOP
A = 5
B = 10.5
C = 'Hello'
D = True
or
A,B,C,D = 5,10.5,'Hello',True
In Explicit Type Conversion, users convert the data type of an object to required data type. We use
the predefined functions like int(), float(), str(), etc to perform explicit type conversion. This
type conversion is also called typecasting because the user casts (change) the data type of the
objects.
A = '100'
print('Datatype of A: ', type(A))
A = int(A)
C = A + 100
print('Datatype of B: ', type(A))
print('Datatype of B: ', type(C))
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 7
CEAT – Engineering Department
Deleting Variables
Deleting variables removing the memory allocation for the variable. Use the command del for deleting
variable.
X = 'Hello World'
print(X)
del X
print(X)
Keywords
Keywords are the reserved words in Python. We cannot use a keyword as variable name, function
name or any other identifier. They are used to define the syntax and structure of the Python language.
In Python, keywords are case sensitive.
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 8
CEAT – Engineering Department
print(message)
Where:
message is the string (enclosed by ‘ ‘), variable, or combination of both (concatenated by +) to
be displayed
START
Declarations
String name = “Joshua Isaguirre”
String course = “BS Computer Engineering”
Output(“My Name is: ” & name)
Output(“My Course is: ” & course)
STOP
Input Streams
To receive an input from the user, the syntax is:
X = input(prompt)
Where:
X is the variable that will receive the input value
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 9
CEAT – Engineering Department
Operators
Operators are syntaxes and symbols used to manipulate and control inputs and variables to produce
the desired output.
Arithmetic Operators
Assignment Operators
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 10
CEAT – Engineering Department
Assigns values from right side operands to left side c = a + b assigns value of
=
operand a + b into c
Relational Operators
If values of two operands are not equal, then (a <> b) is true. This is
<>
condition becomes true. similar to != operator.
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 11
CEAT – Engineering Department
Logical Operators
and Logical If both the operands are true then condition becomes
(a and b) is true.
AND true.
not Logical
Used to reverse the logical state of its operand. Not(a and b) is false.
NOT
EXAMPLE: Input two numbers and display their sum, difference, multiplication and division
START
Declarations
int A, B, sum, diff, prod, quo
Output(“Enter first number: ”)
Input(A)
Output(“Enter second number: ”)
Input(B)
sum = A + B
diff = A – B
prod = A * B
quo = A / B
Output(“The sum is: ” & sum)
Output(“The difference is: ” & diff)
Output(“The product is: ” & prod)
Output(“The quotient is: ” & quo)
STOP
A = int(input('Enter first number: '))
B = int(input('Enter second number: '))
sum = A + B
diff = A - B
prod = A * B
quo = A / B
print('The sum is: ', sum)
print('The difference is: ', diff)
print('The product is: ', prod)
print('The quotient is: ', quo)
T-CPET121LA
Introduction to Computational Thinking