[go: up one dir, main page]

0% found this document useful (0 votes)
25 views11 pages

Python L1

Uploaded by

dwk6nc8ggs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Python L1

Uploaded by

dwk6nc8ggs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PYTHON PROGRAMMING

CS 1214

Algorithms and Pseudo Code

Wanzita Shilla
Assistant. Lecturer
ISNE
The Outline
1. Introduction to Python
2. What is algorithms?
3. What is pseudo code?

TREY
2
research
Introduction to Python

Definition:
Python is a high-level, interpreted programming language known for its simplicity, readability, and
versatility.

Features of Python:
Readability: designed to be easily readable and understandable. It uses indentation to define code blocks,
making it visually clean and intuitive.
Versatility: Multipurpose language used in various domains such as web development, data science,
artificial intelligence, automation, scientific computing, and more. Its extensive standard library and third-
party packages make it suitable for diverse applications.
Interpreted: Executed line by line by the Python interpreter, which converts the code into machine-
readable bytecode. This makes development and debugging easier as code can be tested immediately
without compilation.

TREY
3
research
Introduction to Python

Features of Python:
Dynamic Typing: dynamically typed, meaning you don't need to explicitly declare variable types. Variables
can change type during runtime, offering flexibility but requiring careful attention to data types in certain
situations.
Object-Oriented: Object-oriented programming (OOP) principles such as classes, inheritance, encapsulation,
and polymorphism. This makes it suitable for developing large-scale, modular, and reusable codebases.
Extensive Standard Library: comes with a vast standard library that provides modules and functions for
various tasks like file handling, networking, data processing, and more. This reduces the need for external
dependencies for many common functionalities.
Community and Ecosystem: has a large and active community of developers contributing to its ecosystem.
The availability of third-party libraries and frameworks like NumPy, Pandas, Django, Flask, TensorFlow, and
PyTorch further enhances Python's capabilities for specific domains.

TREY
4
research
What is algorithms?
Algorithms are step-by-step procedures or formulas used for problem-solving and
computation.
In Python programming, algorithms are implemented using functions and control flow
structures like loops and conditional statements.

1. SELECTION SORT ALGORITHM


Sorts an array by repeatedly finding the minimum element from the unsorted part and
swapping it with the first unsorted element.

TREY
5
research
SELECTION SORT ALGORITHM
def selection_sort(arr):
n = len(arr)
for i in range(n):
min_idx = i for j in range(i+1, n):
if arr[j] < arr[min_idx]:
min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i]
return arr

TREY
6
research
INSERTION SORT:
 Builds a sorted list one element at a time by repeatedly taking the next element and inserting it into its
correct position among the already sorted elements.

def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j=i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr

TREY
7
research
SEQUENTIAL SEARCH:

Linear search through a list from start to end to find a target element.

• def linear_search(arr, target):


• for i in range(len(arr)):
• if arr[i] == target:
• return i
• return -1 # Target not found

Add a footer TREY 8


research
PSEUDO CODE
Advantage of Pseudo Code:
 Simplify logic of their program
 Easier to communicate with non-programmers
 Save time and prevent mistakes.

Steps to write a pseudo code


1. Understand the problem you want to solve
 1. write program that adds together two numbers

2. Break down the problem into smaller steps


 2.1 ask the user to input the first number
 2.2 ask user to input the second number
 2.3 add the two numbers together
 2.4 display the sum to the user
TREY
9
research
Steps to write a pseudo code
3. Write the pseudo code
 3.1 display “enter the first number”
 3.2 input the first number from the user and store it in a variable called num1
 3.3 display “enter the second number”
 3.4 input the second number from the user and sore it in a variable called num2
 3.5 add num1 and num2 together and store the result in variable called sum
 3.6 display “the sum of ” + num1 “and” + num2 + “is ” + sum

TREY
10
research
Thank You Wanzita Shilla
+255716578677
elwanzita20s@gmail.com

TREY
11
research

You might also like