Lec-2 Introduction to Python Programming Language
Lec-2 Introduction to Python Programming Language
“ Introduction to
Python } “” [
Programming “
language
From here we will start
BY : Youssef Abdel-mohymen
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Table of contents
{01}
Introduction to Programming
{02}
Introduction to Python
{03}
Syntax and Comments
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Pitch Deck 20xx
“
Introduction to
Programming
01
} “” [
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Central Processing Unit (CPU)
The CPU performs a continuous cycle of the
following operations:
a. Fetch: Retrieves an instruction from
memory.
b. Execute: Interprets and follows the
instruction.
c. Output: Produces and stores the
resulting data.
The CPU is comprised of two main components:
1. Control Unit (CU):
a. Manages and coordinates all of the
computer’s operations.
b. Determines the sequence of
instructions to be executed.
2. Arithmetic and Logic Unit (ALU):
Specialized in performing mathematical and
logical operations, such as addition,
subtraction, multiplication, etc.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Basic Machine Architecture
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Main Memory
Main memory is where information is stored for the CPU to
access and process. It is organized into bytes, each
consisting of 8 bits.
• A bit is the smallest unit of data, representing
either on (1) or off (0).
• Each byte in memory is assigned a unique address,
which allows the CPU to access specific data.
Memory Address: A unique identifier for each byte, enabling
precise data retrieval.
Main memory is typically volatile, meaning its contents are
lost when the power is turned off.
• Volatile Memory: Memory that erases its contents when
power is lost.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Secondary Storage
1. Secondary Storage is memory that can hold data
for a long period of time.
2. Programs are usually stored in secondary
storage and loaded into main memory as needed.
3. Common forms of secondary storage:
a. Hard Drive
i. Disk Drive
i. USB Drives
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Input Devices and Output Devices
“ ** } “” [
Input Devices Output Devices
Input is data from the outside Output is data the computer sends
world sent to the computer by out via output devices like:
input devices like: • Monitor
• Keyboard • Printer
• Mouse • Disk Drive
• Scanner • USB Drive
• Camera
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Software Categories
1. System Software
• Core programs that manage and control
computer hardware.
• Includes operating systems (e.g., Windows,
Unix) and essential tools like compilers.
2. Application Software
• Programs designed to assist users with
specific tasks.
• They solve particular problems or provide
services to enhance user productivity.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Computer Languages
Machine Language Assembly Language High-Level Language (HLL)
”
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
COMPILER
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
A Layered View of the Computer
Application Programs
System Software
Compilers, Operating
System
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Program Development Cycle
Many programmers follow a series of steps to develop their programs:
1. Analyze – Define the Problem
a. Clearly understand the program’s purpose:
i. What inputs should the user provide?
ii. How does the program process these inputs to generate a
solution?
iii.What outputs should the program produce, and in what format?
• User: A person who interacts with the program.
• End User: The specific user for whom the program is designed.
2. Design – Plan a Solution
a. Create a precise sequence of steps (algorithm) to solve the
problem.
b. An algorithm is a detailed, step-by-step plan for achieving the
desired outcome.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Develop an Algorithm
Problem: Create a program to calculate the cost of sending a
package based on weight. The cost is $1 per 5 kg.
Algorithm:
1. Input: Get the weight of the package in kilograms from the user.
2. Calculate Cost:
a. Divide the weight by 5 to determine the number of 5 kg units.
b. Multiply the number of units by $1 to get the total cost.
3. Output: Display the total cost to the user.
Example:
• For a 6 kg package:
a. Number of 5 kg units: 6/5=1.2 (round up to 2 units)
b. Total cost: 2×$1=$2
• For a 12 kg package:
a. Number of 5 kg units: 12/5=2.4 (round up to 3 units)
b. Total cost: 3×$1=$3
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Flow Charts
1.Flow Line - indicates the flow of logic
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Flow Charts
1.Processing - used to show a processing step. The instructions
are displayed in the figure.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Weight Flowchart
Start
No
Display Error Message Is weight +ve number?
Yes
Display cost
End
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Hierarchy Chart
Postage Stamp
Program
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Pitch Deck 20xx
“
Introduction to
Python
02
} “” [
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ What Is Python?
Free and Open Source Interpreted Language
Python is available to everyone, Code is executed line by line,
fostering innovation and making debugging easier and more
collaboration. efficient.
Highly Interactive
Python's interactive mode allows
for quick testing and
experimentation, ideal for
beginners and experts alike.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Why Choose Python?
Simple Installation Readable and Clean Robust Error Handling
Easy to Install: Python’s Clean and Easy Syntax: Effortless Debugging:
installation process is Python’s clear syntax Python’s built-in debugger
straightforward, getting promotes readability, simplifies the process of
you up and running quickly. making code easy to write identifying and fixing
and understand. errors.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ Why Choose Python? 2
Efficient Memory Multi-Purpose
Extensive Libraries Management Language
Large Set of Libraries and Garbage Collection: Versatile Applications:
Plugins: Python provides a Python automatically Python is used in web
vast array of libraries and manages memory, development, data analysis,
plugins, simplifying optimizing performance. AI, automation, and more.
complex tasks.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ What’s Python Used For?
Web Development Game Development
Django & Flask: Python frameworks PyGame: PyGame is a library that
like Django and Flask are used to allows developers to create video
build robust and scalable web games with Python.
applications.
Desktop Applications
PyGUI & Tkinter: These libraries
facilitate the creation of
desktop applications with
graphical user interfaces.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ What’s Python Used For?
Cybersecurity ML & DS
Hacking: Python is used for ethical Machine Learning & Data Science:
hacking and cybersecurity tasks, Python excels with libraries like
including penetration testing and Pandas, NumPy, TensorFlow, and
vulnerability scanning. Scikit-learn.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
“ What’s Python Used For?
Automation Web Scraping
ask Automation: Python scripts can Harvesting Data: Python is widely
automate repetitive tasks such as used for web scraping to extract
file management, data processing, data from websites.
and system administration, saving
time and reducing human error.
Android Game Development
Game Creation for Android:
Python’s Kivy library allows for
building Android games and apps.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Some Apps Use Python
1. YouTube: Largest video-sharing platform with billions of users.
2. Facebook: Major social networking site with billions of active
users.
3. Instagram: Popular social media platform with over a billion
users.
4. Amazon: Leading e-commerce platform used by millions globally.
5. Netflix: Widely used streaming service with hundreds of
millions of subscribers.
6. Spotify: Leading music streaming service with millions of
users.
7. Google: Essential search engine and various services used
globally.
8. Uber: Major ride-sharing service with a large user base.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Pitch Deck 20xx
“
Syntax and
Comments
03
} “” [
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Python Basics Syntax
The print() Function:
In Python, ‘print()’ is a built-in function used to
output text or other data to the console.
Explanation:
• print("I Love Python"): This line prints the text "I Love Python" to the
console.
• print("I Love Programming"): This line prints the text "I Love Programming"
to the console.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Python Basics Syntax
Indentation in Python
Python uses indentation to define blocks of code. Indentation is
crucial for Python’s syntax and determines the grouping of
statements.
if True:
print("I Love Python")
print("I Love Programming")
• Explanation:
• The if True: statement is followed by an indented block of code.
• Both print() statements are indented to show they are part of the if block.
• Python uses indentation (typically 4 spaces) to group statements and define code
blocks.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Python Basics Syntax
Incorrect Indentation:
if True:
print("I Love Python")
print("I Love Programming") # This line will cause an indentation error
Explanation:
• The second print() statement is misaligned with the first.
• Consistent indentation is required; inconsistent indentation will
cause a syntax error.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Python Basics Syntax
Code Blocks:
A block of code is a group of statements that are executed together. In
Python, blocks are created using indentation.
def greet():
print("Hello, World!") # This line is part of the greet() block
print("Welcome to Python!")
greet()
Explanation:
• The ‘def greet()’: line starts a new block of code.
• The indented lines following def greet(): are part of the greet
function block.
• The greet() function is called to execute the statements within the
block.
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Comments in Python
Purpose of Comments:
Provide Information About the File
• License details
• Author of the file
• Creation date
• Purpose of the file
Types of Comments:
1.Single-Line Comments
• Writing Beside a Programming Line
print("I Love Python") # This is an inline comment
• Writing Before a Programming Line
# This is a comment explaining the next line
print("Programming")
• Prevent Code From Running
# print("This line won't run because it's commented out")
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Understanding Comments in Python
• Documenting Code Reasoning
print("Programming") # I used this method because of X, Y, Z
print("Programming") # If you use the test method, it will throw an error
2. Multi-Line Strings (Not for Comments)
• Sometimes used mistakenly as comments:
"""
This is not a proper way
to write multi-line comments
"""
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
Pitch Deck 20xx
“ Thanks! } “” [
Do you have any questions?
“
CREDITS: This presentation template was
created by Slidesgo, and includes icons
by Flaticon, and infographics & images
by Freepik
1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1