Python Lecture 01
Python Lecture 01
in
Python
1
programming languages vs Natural
languages
2
◼ Language consists of the four elements
3
4
Evolution of computer languages
5
6
Program in machine language
7
Note
:
The only language understood by
a computer is machine language.
8
Program in Assembly language
END
9
◼ Assembly language is one level above machine language.
10
High level Language
▪ Machine Independent Language.
▪ The file containing the source code is called the source file.
11
Compiling and interpreting
◼ Many languages require you to compile (translate) your program
into a form that the machine understands.
compile execute
source code byte code output
Hello.java Hello.class
interpret
source code output
Hello.py
12
13
Languages
▪ Algorithmic languages (LISP,ALGOL)
▪ Business-oriented languages(COBOL,SQL)
▪ Education-oriented languages(BASIC,Pascal)
▪ Declarative languages
14
Programs and Programming
❑ A (software) program is an ordered sequence of instructions that
the hardware of a computer can execute.
15
Program Development steps
1. Define the problem
2. Outline the solution
3. Develop an algorithm
4. Test the algorithm for correctness
5. Code the algorithm in a programming language to obtain a
program
6. Ensure program has no syntax errors
7. Compile to generate translated code (optional)
8. Run the program
9. Test and debug the program
10. Document and maintain the program
16
Define the Problem
❑ The problem can be divided into three components
17
Outline the Solution
◼ the major computational tasks and any subtasks
◼ the major variables and data structures (to store data; e.g., inputs,
intermediate results)
◼ the control structures (e.g., sequence, selection, repetition) that can be
used
Consider the above example. The processing required is to compute c = 2πr and a = πr2.
▪ In order to calculate the circumference:
➢ Computation – c = 2πr
➢ Computation – a = πr2
18
Develop an Algorithm
◼ complex problem, developing an algorithm is generally more difficult
than obtaining a computer program by coding an algorithm.
◼ used to express an algorithm
2. Flowcharts
19
Pseudocode
◼ Pseudocode (a structured form of the English language) can be used to
express an algorithm.
Step 1. Start
2. Input r
3. Compute circumference
c = 2 * PI * r
4. Compute area
a = PI * r * r
5. Output c and a
6. Stop
‘PI’ is a constant that represents the value of π and ‘*’ is the multiplication operator.
20
flowcharts
◼ Another tool that can be used to express algorithms
◼ A flowchart is an easy to understand pictorial representation of an
algorithm.
21
Start
Input radius r
C=2*PI*r
A=PI*r
Output C and a
Stop
22
Start 1. Start
2. Num =1
Total = 0
Num=1 3. Total =Total + Num
Total=0
Num = Num + 1
4. If Num ≤ 100
Total=Total+Num
go to Step 3 // implied: else continue to Step 5
Num<=100
Yes
No
Output Total
Stop
23
Q. Draw a Pseudocode and flowchart to log in to Facebook account
24
25
Q. Find the sum of 5 numbers
1.Start
2.Initialize sum = 0 and count = 0 (PROCESS)
3.Enter n (I/O)
4.Find sum + n and assign it to sum and then increment count by 1 (PROCESS)
5.Is count < 5 (DECISION)
if YES go to step 2
else
Print sum (I/O)
6.Stop
26
27
Test the Algorithm for Correctness
◼ The programmer must make sure that the algorithm is correct
◼ Correction is easy.
28