241Algorithms Python
241Algorithms Python
Basics of Algorithms
Representing Algorithms
Introduction to Python Programming
Variables and Data Types
2
Introduction to Algorithms
3
Qualities of a good algorithm
4
Different ways of representing algorithm
Pseudocode
The pseudocode is a written form
representation of the algorithm.
Flowchart
Flowchart is graphical representation of
algorithms.
5
Pseudocode (Example of Algorithm)
6
Flowchart
7
Symbols Used In Flowchart
8
Example of flowchart
Draw a flowchart to find average of two numbers entered by user.
Start
Input num1
Input num2
Output Average
End
9
Python Programming
10
Variables
11
Variables
12
Variables Types
Variables can hold different types of data
name = 'Ahmed'
name Ahmed
In the notebook, you can show the variables declared in
the program and their types when you click on {x}.
x=5 Integer
13
Variable Input
Input numbers
input() functions always return string (text) value
To get numbered input we can use the int (convert to
integer) or float (convert to real number with decimal
point) functions
Output:
Enter side of a square:4
16
14
Python Arithmetic Operators
Arithmetic operation Python symbol Output
Addition 9+6 15
Subtraction 9–6 3
Multiplication 9*6 54
Division 9/6 1.5
Floor division 9 // 6 1
Remainder 9%6 3
Exponentiation 9 ** 6 531441
Order of evaluation:
1. Exponentiation
2. Division, multiplication, remainder
3. Addition and subtraction
15
Python modules
16
Python Programming
17
Combining text and variable in
print
18
Review Questions
19