Week2-Programming in Python
Week2-Programming in Python
Programming in Python
Learning Outcomes
At the end of this module, you will:
➢ Review the fundamentals of computer programming
➢ Review the Three Basic Programming Structures
➢ Explain the difference between compilation and
interpretation
➢ Identify essential differences between Python and Java
➢ Be able to create and execute a Python program
Fundamental of Computer Programming
Computer Programming
- Writing instruction or code that a computer can execute to
perform specific tasks.
Data Structure
Fundamental of Computer Programming
Algorithm
- A step-by-step to solve a problem or performing a
computation.
Flowchart
- Visual tools that understand and represent processes using
symbols such as arrows, rectangles and diamonds show
steps and decision clearly.
Data Structure
Fundamental of Computer Programming
Programming Languages
- Languages are used to write codes
1. Low-Level Languages
- Machine Language uses binary (0 and 1)
- Assembly Code ( short codes)
2. High-Level Languages (e.g. C, Java, Python)
- Easy for human to read,
write, and understand Data Structure
Fundamental of Computer Programming
Syntax
- Rules defining how code should be written.
Semantics
- Meaning of the written code.
Data Structure
Fundamental of Computer Programming
Different ways to approach programming:
Data Structure
Fundamental of Computer Programming
Variables
- store values in memory.
- characteristics or attribute that can take on different
values or be measured.
Data types
- define the kind of data (e.g., int, float, string, boolean).
Data Structure
Fundamental of Computer Programming
Operators
- Used for computations:
Arithmetic Operators
- Basic Mathematical Calculations (+, -, *, /)
Relational Operators
- Comparing two values and return true or false (==, !=,
<, >)
Logical Operators
- Combining or modify Boolean expression (&&, ||, !)
Data Structure
Fundamental of Computer Programming
Functions
- Reusable blocks of code that perform a specific task.
Data Structure
Fundamental of Computer Programming
Program Development Process
1.Problem Definition – Understanding what needs to be solved.
2.Algorithm Design – Creating a step-by-step solution.
3.Coding – Writing the program using a programming language.
4.Compilation & Execution – Converting code into machine-readable form.
5.Testing & Debugging – Finding and fixing errors.
6.Maintenance – Updating and improving the program.
Data Structure
Fundamental of Computer Programming
Debugging and Error Handling
- Finding and fixing error (bugs) in code.
Syntax Errors
- Syntax violations that prevent code from executing
Logical Errors
- Incorrect logical flaws that leads to unintended behavior in
the program.
Runtime Errors
- Errors that occur while the program is running
Data Structure
Fundamental of Computer Programming
Computer Programming
Writing instruction or code that a computer can execute to
perform specific tasks.
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Sequence Structure
Simplest structure where the execution of code line by
line or one after another in a linear order.
Data Structure
Three Basic Programming Structures
Sequence Structure
print("Welcome to Python Programming")
name = input("Enter your name: ")
print(f"Hello, {name}! Have a great day!")
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Data Structure
Three Basic Programming Structures
Data Structure
The Difference between Compilation and Interpretation
Compilation
- Translate the codes into machine
code (binary code)
- Errors are detected before the
execution.
Data Structure
The Difference between Compilation and Interpretation
Interpretation
- Translate and execute the source
code line by line.
- Errors are detected during
execution
Data Structure
Essential Differences between Python and Java
Data Structure
Essential Differences between Python and Java
Java
- Syntax Strict with using curly braces {} and semicolons.
- Compiled into bytecode
- Executed by the Java Virtual Machine (JVM)
- High Performance, developing large-scale applications
like enterprise software.
Data Structure
Essential Differences between Python and Java
Python
- Simple and easy to read
- Interpreted languages (executed line by line)
- Best for automation, data science, AI, and
web development)
Data Structure
Essential Differences between Python and Java
Python
Print(“Hello, World!”)
Java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!"); }}
Data Structure
Arrays (Lists, Tuple, Dictionary)
What is a List?
• Most basic structure for storing and accessing a collection of
data
• is a mutable sequence container that can
change size as items are added or removed.
• It is an abstract data type that is
implemented using an array structure to store the items
contained in the list
• They helped you keep related data together and perform the
same operations on several values at once.
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
Combining Lists
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
list_variable(start:stop:step)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
Method
List – Built-In Function
Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified
value
extend() Add the elements of a list (or any iterable), to the end
of the current list
index() Returns the index of the first element with the
specified value
insert() Adds an element at the specified position
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
What is a Tuple?
• Similar to lists – they allow you to display an
ordered sequence of elements.
• However, they are immutable, and you can’t
change the values stored in a tuple.
DASTRUC
Arrays (Lists, Tuple, Dictionary)
Examples
DASTRUC
Arrays (Lists, Tuple, Dictionary)
What is a Dictionary?
• is used to store the data in a key-value pair format. These key-
value pairs offer a great way of organizing and storing data in
Python.
• an unordered collection of key-value pairs. It is a data structure
that allows you to store and retrieve values based on a unique
key
• is a mutable sequence container that can
change size as items are added or removed.
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)
DASTRUC
Arrays (Lists, Tuple, Dictionary)