SlideShare a Scribd company logo
Chapter 1 Introduction to Computers,
Programs, and Python
Applied Programming
Course Supervisor: Syed Muhammad Hassan
1
Grading
• Quizzes = 10%
• Assignments = 10%
• Project = 15%
• Class Participation = 5%
• Midterm = 20%
• Final Exam = 40%
2
3
Textbook:
• Programming in Python 3: A Complete Introduction to the Python
Language, Second Edition, Mark Summerfield, 2010.
Reference Books:
• Introduction to Programming using Python, Y. Daniel Liang, 1st
edition, 2017.
• Introduction to Computer Science Using Python: A Computational
Problem-Solving Focus by Charles Dierbach, Wiley 2013.
• Automate the Boring Stuff with Python by Al Sweigart, 2015.
• Python for Everybody by Charles R. Severance.
4
Programs
Computer programs, known as software, are instructions
to the computer.
You tell a computer what to do through programs. Without
programs, a computer is an empty machine. Computers do
not understand human languages, so you need to use
computer languages to communicate with them.
Programs are written using programming languages.
Characteristics of successful computer
program
• Correct: it does what is supposed to do
• Usable: it is easy to use
• Reliable: it works without failing
• Understandable: it can be easily comprehended
• Modifiable: it can be enhanced and updated
• Maintainable: it can be corrected when errors are found
• Flexible: it can be modified to supply other information as required
• General: it is not too specialized
• Efficient: it does not waste computer resources
5
Five main steps in programming process
1.Defining the problem: Suppose that, as a programmer, you are
contacted because your services are needed. You meet with users
from the client organization to analyze the problem, or you meet
with a systems analyst who outlines the project. Specifically, the
task of defining the problem consists of :
• determining program objectives,
• identifying what it is you know (input-given data),
• what it is you want to obtain (output-the result),
• determining processing requirements.
• Eventually, you produce a written agreement that, among other
things, specifies the kind of input, processing, and output required.
This is not a simple process.
6
Five main steps in programming process
2.Planning the solution: Once the programmer has determined what
the program must do, the next step is to plan a solution, preferably
using structured programming techniques or program design tools.
Three common ways of planning the solution to a problem are top-
down program design, to write algorithm and to draw a flowchart.
a.Top-down program design (Modularization): It is a type of Modular
Programming Approach. Once you have determined the outputs and
inputs, you can use top-down program design or top-down
decomposition to identify the program’s processing steps. Such
steps are called program modules. Each module is made up of
logically related program statements. Procedural programming
follows this approach.
7
8
Fig 1.1 shows an example of top down
program design for a payroll report. Each of
boxes shown is a module or, in the lower
part, a sub-module.
Bottom-up technique:
Top-down program design
Fig 1.1
For example: Given a list of students’ test
scores, find the highest and lowest score and
the average score. Sub-problem 1: read
students’ scores. Sub-problem 2: find highest
score. Sub-problem 3: find lowest score.
Sub-problem 1 can be considered as one
action and therefore needs no further
refinement. Sub-problems 2 and 3 however
can be further divided into a group of
actions.
Five main steps in programming process
b. Algorithm:
• It is a step by step method of designing a program using normal
human language statements.
• It describes the logic and processing flow of a program.
• Algorithm is like an outline or summery form of the program you will
write.
9
Sample Algorithm
• Task: add two numbers
• Algorithm :
1. Start
2. Get two numbers
3. Add them (a + b)
4. Print the answer
5. End
10
What does a flowchart look like?
• Algorithm :
1.Start
2.Get two numbers
3.Add them (A + B)
4.Print the answer
5.End
Start
Get 2 numbers
A+B
Print answer
End
11
Five main steps in programming process
c. Flowchart:
• Flowchart is a pictorial representation of a step-by-step solution to a
problem.
• It consists of arrows representing the direction the program takes and
boxes and other symbols representing actions.
• It is a map of what your program is going to do and how it is going to
do it.
• The American National Standards Institute (ANSI) has developed a
standard set of flowchart symbols. Figure 1.2 shows the symbols and
how they might be used in a simple flowchart of a common everyday
act-preparing a letter for mailing.
12
13
Flowchart Symbols
Fig 1.2: Flowchart Symbols
14
Fig 1.3: Flowchart for Mailing Letter
Fig: 1.4: Flowchart for reading temperature
Five main steps in programming process
3.Coding the program:
• As the programmer, your next step is to code the program-that is, to
express your solution in a programming language.
• You will translate the logic from the flowchart or pseudocode-or some
other tool-to a programming language.
4.Testing the program: Eventually, after coding the program, you must
prepare to test it on the computer. This step involves these phases:
• Desk-checking. This phase, similar to proof reading, is sometimes avoided
by the programmer who is looking for a shortcut and is eager to run the
program on the computer once it is written. In desk-checking you simply sit
down and mentally trace, or check, the logic of the program to attempt to
ensure that it is error-free and workable.
15
Five main steps in programming process
• Translating. A translator is a program that checks the syntax of
your program to make sure the programming language was used
correctly, giving you all the syntax-error messages, called
diagnostics, and then translates your program into a form the
computer can understand.
• The translator tells you if you have improperly used the
programming language in some way. These types of mistakes are
called syntax errors.
• The translator produces descriptive error messages. For example,
if you mistakenly write N=2 *(I+J))-which has two closing
parentheses instead of one-you will get a message that says,
"UNMATCHED PARENTHESES.“
16
Five main steps in programming process
• Programs are most commonly translated by a compiler. A compiler
translates your entire program at one time. The translation involves your
original program, called a source module, which is transformed by a
compiler into an object module.
• Prewritten programs from a system library may be added during the
link/load phase, which results in a load module. The load module can then
be executed by the computer.
• Debugging. A term used extensively in programming, debugging means
detecting, locating, and correcting bugs (mistakes), usually by running the
program. These bugs are logic errors, such as telling a computer to repeat
an operation but not telling it how to stop repeating. In this phase you run
the program using test data that you devise. You must plan the test data
carefully to make sure you test every part of the program.
17
Five main steps in programming process
5. Documenting the Program: Documentation is a written detailed
description of the programming cycle and specific facts about the
program. Typical program documentation materials include the
origin and nature of the problem, a brief narrative description of
the program, logic tools such as flowcharts and pseudocode,
data-record descriptions, program listings, and testing results.
Comments in the program itself are also considered an essential
part of documentation.
18
Computer Programming Constructs/Control Constructs
Structured Programming Constructs:
1. Sequence Control Structure (Sequence Logic or Sequential Flow).
2. Selection Control Structure (Selection Logic or Conditional Flow).
3. Repetition Control Structure (Iteration Logic or Repetitive Flow).
1. Sequence Control Structure (Sequence Logic or Sequential Flow):
If nothing is specified then the modules are executed in the sequence in which
they are written. Thus in it the modules are executed one after the other.
The sequence control structure is shown below:
Algorithm
.
.
.
Module A
Module B
Module C
.
. 19
2. Selection Control Structure (Selection Logic or Conditional Flow):
In it there are various conditions on the basis of which one
module is selected out of several given modules. The structures
which implement this logic are called conditional structures. The
conditional structures can be divided into following categories:
1. Single Alternative: This structure has the following form:
If condition, then
[Module A]
[End of If structure]
20
According to this if the condition is true then
module A is executed. Otherwise, module A is
skipped. Its flowchart is:
2. Double Alternative: This structure has the
following form:
If condition, then
[Module A]
Else
[Module B]
[End of If structure]
According to this if the condition is true then
module A is executed. Otherwise, module B
is executed. 21
Single Alternative(cont.)
3. Multiple Alternative: This structure has the following form:
If condition (1), then
[Module A1]
Else If condition (2), then
[Module A2]
.
.
.
Else If condition (n), then
[Module An]
Else
[Module B]
[End of If structure]
22
Multiple Alternative (cont.)
According to this only one of the modules will be executed. If condition 1 is true then module A1 will be executed.
Otherwise condition 2 will be checked. If condition 2 is true then module A2 will be executed. And so on. If none of
the conditions is true then module B will be executed. Its flowchart is:
23
4. Repetition Control Structure (Iteration Logic or Repetitive Flow): In
this structure, loops are implemented. Loop is used to implement
those statements which are to be repeated again and again until
some condition is satisfied. It implements while and for loops. Each
of these begin with Repeat statement. For example is case of Repeat-
while structure:
Repeat steps 1 to n while condition:
[Steps]
[End of Repeat-while structure]
Its flowchart is:
24
25
Programming Languages
Machine Language Assembly Language High-Level Language
Machine language is a set of primitive instructions
built into every computer. The instructions are in
the form of binary code, so you have to enter binary
codes for various instructions. Program with native
machine language is a tedious process. Moreover
the programs are highly difficult to read and
modify. For example, to add two numbers, you
might write an instruction in binary like this:
1101101010011010
26
Programming Languages
Machine Language Assembly Language High-Level Language
Assembly languages were developed to make programming
easy. Since the computer cannot understand assembly
language, however, a program called assembler is used to
convert assembly language programs into machine code.
For example, to add two numbers, you might write an
instruction in assembly code like this:
ADDF3 R1, R2, R3
…
ADDF3 R1, R2, R3
…
Assembly Source File
Assembler …
1101101010011010
…
Machine Code File
27
Programming Languages
Machine Language Assembly Language High-Level Language
The high-level languages are English-like and easy to learn
and program. For example, the following is a high-level
language statement that computes the area of a circle with
radius 5:
area = 5 * 5 * 3.1415;
28
Popular High-Level Languages
•COBOL (COmmon Business Oriented Language)
•FORTRAN (FORmula TRANslation)
•BASIC (Beginner All-purpose Symbolic Instructional Code)
•Pascal (named for Blaise Pascal)
•Ada (named for Ada Lovelace)
•C (whose developer designed B first)
•Visual Basic (Basic-like visual language developed by Microsoft)
•Delphi (Pascal-like visual language developed by Borland)
•C++ (an object-oriented language, based on C)
•C# (a Python-like language developed by Microsoft)
•Python (We use it in the book)
Programming Languages
• High level programming languages: is languages program than use
languages or syntax which closes to human languages so; it is easy to
understanding the languages. This type of language is machine-
independent, and uses similar language as English, which is easily
understandable by human.
Types of high level languages are:
1) Procedural Languages
2) Functional & Non procedural Languages
3) Object Oriented Languages
29
Levels of Programming Languages
High-level program class Triangle {
...
float surface()
return b*h/2;
}
Low-level program LOAD r1,b
LOAD r2,h
MUL r1,r2
DIV r1,#2
RET
Executable Machine code 0001001001000101001001
001110110010101101001.
..
30
Procedural programming languages
• Procedural language is a type of computer programming language that
specifies a series of well-structured steps and procedures within its
programming context to compose a program. It contains a systematic
order of statements, functions and commands to complete a
computational task or program.
• Procedural language is also known as imperative language.
• Procedural languages are:
• C/C++ Language
• FORTRAN (FORmula TRANslation)
• BASIC (Beginners All Purpose Symbolic Instruction Code)
• COBOL (Common Business Oriented Language) These types of
languages are “Third-Generation Language”.
31
Non Procedural Languages
• In non-procedural languages the computer is not limited to a set of
precise instructions. Instead, the programmer defines only the
problem—not the instructions--to solve the problem. Non Procedural
Programming Languages are:
• SQL (Structured Query Language)
• LISP (List Processing)
• PROLOG (PROgramming with LOGic)
32
Object Oriented Programming
• Object-oriented programming (OOP) is an engineering
approach for building software systems
• Based on the concepts of classes and objects that are used for modeling the
real world entities
• A program models a world of interacting objects
• Objects create other objects and “send messages” to each other (in
Java, call each other’s methods)
• Each object belongs to a class
• A class defines properties of its objects
• The data type of an object is its class
• Programmers write classes (and reuse existing classes)
• All modern languages are object-oriented: Java, C#, PHP (Hypertext
Preprocessor), Perl (Practical Extraction and Reporting Language),
C++, ...
33
Compiling Source Code
A program written in a high-level language is called a
source program. Since a computer cannot understand a
source program. Program called a compiler is used to
translate the source program into a machine language
program called an object program. The object program is
often then linked with other supporting library code
before the object can be executed on the machine.
Compiler
Source File Machine-language
File
Linker Executable File
Library Code
34
Operating Systems
The operating system (OS) is
a program that manages and
controls a computer’s
activities. You are probably
using Windows 98, NT, 2000,
XP, or ME Etc. Windows is
currently the most popular
PC operating system.
Application programs such as
an Internet browser and a
word processor cannot run
without an operating system.
User
Application Programs
Operating System
Hardware
35
36
What is Python?
General Purpose Interpreted Object-Oriented
Python is a general purpose programming language.
That means you can use Python to write code for
any programming tasks. Python are now used in
Google search engine, in mission critical projects in
NASA, in processing financial transactions at New
York Stock Exchange.
37
What is Python?
General Purpose Interpreted Object-Oriented
Python is interpreted, which means that python
code is translated and executed by an interpreter
one statement at a time. In a compiled language, the
entire source code is compiled and then executed
altogether.
38
What is Python?
General Purpose Interpreted Object-Oriented
Python is an object-oriented programming
language. Data in Python are objects created from
classes. A class is essentially a type that defines the
objects of the same kind with properties and
methods for manipulating objects. Object-oriented
programming is a powerful tool for developing
reusable software.
39
Python’s History
• created by Guido van Rossum in Netherlands in 1990
• Open source
Python 2 vs. Python 3
Python 3 is a newer version, but it is not
backward compatible with Python 2. That
means if you write a program using Python
2, it may not work on Python 3.
40
Launch Python
41
Launch Python IDLE
42
Run Python Script
43
A Simple Python Program
# Display two messages
print("Welcome to Python")
print("Python is fun")
Run
Welcome
Listing 1.1
IMPORTANT NOTE:
(1) To enable the buttons, you must download the entire slide
file slide.zip and unzip the files into a directory (e.g.,
c:slide). (2) You must have installed Python and set python
bin directory in the environment path. (3) If you are using
Office 2010, check PowerPoint2010.doc located in the
same folder with this ppt file.
44
Creating and Editing Using Notepad
To use Notepad, type
notepad Welcome.py
from the DOS prompt.
45
# Display two messages
print("Welcome to Python")
print("Python is fun")
Trace a Program Execution
Execute a statement
46
# Display two messages
print("Welcome to Python")
print("Python is fun")
Trace a Program Execution
Execute a statement
47
Anatomy of a Python Program
• Statements
• Comments
• Indentation
48
# Display two messages
print("Welcome to Python")
print("Python is fun")
Statement
A statement represents an action or a sequence of
actions. The statement print("Welcome to Python") in
the program in Listing 1.1 is a statement to display the
greeting "Welcome to Python“.
49
# Display two messages
print("Welcome to Python")
print("Python is fun")
Indentation
The indentation matters in Python. Note that the
statements are entered from the first column in the new
line. It would cause an error if the program is typed as
follows:
50
Special Symbols
Character Name Description
()
#
" "
''' '''
Opening and closing
parentheses
Pound sign
Opening and closing
quotation marks
Opening and closing
quotation marks
Used with functions.
Precedes a comment line.
Enclosing a string (i.e., sequence of characters).
Enclosing a paragraph comment.
51
Programming Style and
Documentation
• Appropriate Comments
• Proper Indentation and Spacing
Lines
52
Appropriate Comments
Include a summary at the beginning of the program to
explain what the program does, its key features, its
supporting data structures, and any unique techniques it
uses.
Include your name, class section, instructor, date, and a
brief description at the beginning of the program.
53
Proper Indentation and Spacing
• Indentation
• Indent four spaces.
• A consistent spacing style makes programs clear and
easy to read, debug, and maintain.
• Spacing
• Use blank line to separate segments of the code.
54
Programming Errors
• Syntax Errors
• Error in code construction
• Runtime Errors
• Causes the program to abort
• Logic Errors
• Produces incorrect result

More Related Content

Similar to Programming_Lecture_1.pptx

Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
Alok Jain
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer ProgrammingProf. Erwin Globio
 
Development of computer program
Development of computer program Development of computer program
Development of computer program
UsamaRaja6
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
Prof. Dr. K. Adisesha
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
SherinRappai1
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
SherinRappai
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
AnuragJoshi813963
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
TejaswiB4
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
Mani Kandan
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
Seble Nigussie
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
umardanjumamaiwada
 
lecture 5
 lecture 5 lecture 5
lecture 5
umardanjumamaiwada
 
PCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptxPCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptx
sudharsanm56
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' programSahithi Naraparaju
 
PROBLEM SOLVING
PROBLEM SOLVINGPROBLEM SOLVING
PROBLEM SOLVING
shahzadebaujiti
 
Grade 10 program development cycle
Grade 10   program development cycleGrade 10   program development cycle
Grade 10 program development cycle
Rafael Balderosa
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
lekha572836
 
Software develop....
Software develop.... Software develop....
Software develop....
GCWUS
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software developmentHattori Sidek
 

Similar to Programming_Lecture_1.pptx (20)

Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Development of computer program
Development of computer program Development of computer program
Development of computer program
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
PCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptxPCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptx
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
 
PROBLEM SOLVING
PROBLEM SOLVINGPROBLEM SOLVING
PROBLEM SOLVING
 
Grade 10 program development cycle
Grade 10   program development cycleGrade 10   program development cycle
Grade 10 program development cycle
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Software develop....
Software develop.... Software develop....
Software develop....
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
 

Recently uploaded

Exploring the Future of Smart Garages.pdf
Exploring the Future of Smart Garages.pdfExploring the Future of Smart Garages.pdf
Exploring the Future of Smart Garages.pdf
fastfixgaragedoor
 
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
7sd8fier
 
Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
aaryangarg12
 
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
h7j5io0
 
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
smpc3nvg
 
20 slides of research movie and artists .pdf
20 slides of research movie and artists .pdf20 slides of research movie and artists .pdf
20 slides of research movie and artists .pdf
ameli25062005
 
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
9a93xvy
 
一比一原版(毕业证)长崎大学毕业证成绩单如何办理
一比一原版(毕业证)长崎大学毕业证成绩单如何办理一比一原版(毕业证)长崎大学毕业证成绩单如何办理
一比一原版(毕业证)长崎大学毕业证成绩单如何办理
taqyed
 
Borys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior designBorys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior design
boryssutkowski
 
Top 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen DesignsTop 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen Designs
Finzo Kitchens
 
Research 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdfResearch 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdf
ameli25062005
 
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
ameli25062005
 
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdfPORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
fabianavillanib
 
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Mansi Shah
 
Can AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI preludeCan AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI prelude
Alan Dix
 
Expert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting ServicesExpert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting Services
ResDraft
 
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
jyz59f4j
 
Portfolio.pdf
Portfolio.pdfPortfolio.pdf
Portfolio.pdf
garcese
 
CA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfCA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdf
SudhanshuMandlik
 
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
h7j5io0
 

Recently uploaded (20)

Exploring the Future of Smart Garages.pdf
Exploring the Future of Smart Garages.pdfExploring the Future of Smart Garages.pdf
Exploring the Future of Smart Garages.pdf
 
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
一比一原版(MMU毕业证书)曼彻斯特城市大学毕业证成绩单如何办理
 
Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
 
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
一比一原版(UCB毕业证书)伯明翰大学学院毕业证成绩单如何办理
 
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
一比一原版(Bristol毕业证书)布里斯托大学毕业证成绩单如何办理
 
20 slides of research movie and artists .pdf
20 slides of research movie and artists .pdf20 slides of research movie and artists .pdf
20 slides of research movie and artists .pdf
 
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
一比一原版(RHUL毕业证书)伦敦大学皇家霍洛威学院毕业证如何办理
 
一比一原版(毕业证)长崎大学毕业证成绩单如何办理
一比一原版(毕业证)长崎大学毕业证成绩单如何办理一比一原版(毕业证)长崎大学毕业证成绩单如何办理
一比一原版(毕业证)长崎大学毕业证成绩单如何办理
 
Borys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior designBorys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior design
 
Top 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen DesignsTop 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen Designs
 
Research 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdfResearch 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdf
 
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
 
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdfPORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
 
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
 
Can AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI preludeCan AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI prelude
 
Expert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting ServicesExpert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting Services
 
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
 
Portfolio.pdf
Portfolio.pdfPortfolio.pdf
Portfolio.pdf
 
CA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfCA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdf
 
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
 

Programming_Lecture_1.pptx

  • 1. Chapter 1 Introduction to Computers, Programs, and Python Applied Programming Course Supervisor: Syed Muhammad Hassan 1
  • 2. Grading • Quizzes = 10% • Assignments = 10% • Project = 15% • Class Participation = 5% • Midterm = 20% • Final Exam = 40% 2
  • 3. 3 Textbook: • Programming in Python 3: A Complete Introduction to the Python Language, Second Edition, Mark Summerfield, 2010. Reference Books: • Introduction to Programming using Python, Y. Daniel Liang, 1st edition, 2017. • Introduction to Computer Science Using Python: A Computational Problem-Solving Focus by Charles Dierbach, Wiley 2013. • Automate the Boring Stuff with Python by Al Sweigart, 2015. • Python for Everybody by Charles R. Severance.
  • 4. 4 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. Programs are written using programming languages.
  • 5. Characteristics of successful computer program • Correct: it does what is supposed to do • Usable: it is easy to use • Reliable: it works without failing • Understandable: it can be easily comprehended • Modifiable: it can be enhanced and updated • Maintainable: it can be corrected when errors are found • Flexible: it can be modified to supply other information as required • General: it is not too specialized • Efficient: it does not waste computer resources 5
  • 6. Five main steps in programming process 1.Defining the problem: Suppose that, as a programmer, you are contacted because your services are needed. You meet with users from the client organization to analyze the problem, or you meet with a systems analyst who outlines the project. Specifically, the task of defining the problem consists of : • determining program objectives, • identifying what it is you know (input-given data), • what it is you want to obtain (output-the result), • determining processing requirements. • Eventually, you produce a written agreement that, among other things, specifies the kind of input, processing, and output required. This is not a simple process. 6
  • 7. Five main steps in programming process 2.Planning the solution: Once the programmer has determined what the program must do, the next step is to plan a solution, preferably using structured programming techniques or program design tools. Three common ways of planning the solution to a problem are top- down program design, to write algorithm and to draw a flowchart. a.Top-down program design (Modularization): It is a type of Modular Programming Approach. Once you have determined the outputs and inputs, you can use top-down program design or top-down decomposition to identify the program’s processing steps. Such steps are called program modules. Each module is made up of logically related program statements. Procedural programming follows this approach. 7
  • 8. 8 Fig 1.1 shows an example of top down program design for a payroll report. Each of boxes shown is a module or, in the lower part, a sub-module. Bottom-up technique: Top-down program design Fig 1.1 For example: Given a list of students’ test scores, find the highest and lowest score and the average score. Sub-problem 1: read students’ scores. Sub-problem 2: find highest score. Sub-problem 3: find lowest score. Sub-problem 1 can be considered as one action and therefore needs no further refinement. Sub-problems 2 and 3 however can be further divided into a group of actions.
  • 9. Five main steps in programming process b. Algorithm: • It is a step by step method of designing a program using normal human language statements. • It describes the logic and processing flow of a program. • Algorithm is like an outline or summery form of the program you will write. 9
  • 10. Sample Algorithm • Task: add two numbers • Algorithm : 1. Start 2. Get two numbers 3. Add them (a + b) 4. Print the answer 5. End 10
  • 11. What does a flowchart look like? • Algorithm : 1.Start 2.Get two numbers 3.Add them (A + B) 4.Print the answer 5.End Start Get 2 numbers A+B Print answer End 11
  • 12. Five main steps in programming process c. Flowchart: • Flowchart is a pictorial representation of a step-by-step solution to a problem. • It consists of arrows representing the direction the program takes and boxes and other symbols representing actions. • It is a map of what your program is going to do and how it is going to do it. • The American National Standards Institute (ANSI) has developed a standard set of flowchart symbols. Figure 1.2 shows the symbols and how they might be used in a simple flowchart of a common everyday act-preparing a letter for mailing. 12
  • 13. 13 Flowchart Symbols Fig 1.2: Flowchart Symbols
  • 14. 14 Fig 1.3: Flowchart for Mailing Letter Fig: 1.4: Flowchart for reading temperature
  • 15. Five main steps in programming process 3.Coding the program: • As the programmer, your next step is to code the program-that is, to express your solution in a programming language. • You will translate the logic from the flowchart or pseudocode-or some other tool-to a programming language. 4.Testing the program: Eventually, after coding the program, you must prepare to test it on the computer. This step involves these phases: • Desk-checking. This phase, similar to proof reading, is sometimes avoided by the programmer who is looking for a shortcut and is eager to run the program on the computer once it is written. In desk-checking you simply sit down and mentally trace, or check, the logic of the program to attempt to ensure that it is error-free and workable. 15
  • 16. Five main steps in programming process • Translating. A translator is a program that checks the syntax of your program to make sure the programming language was used correctly, giving you all the syntax-error messages, called diagnostics, and then translates your program into a form the computer can understand. • The translator tells you if you have improperly used the programming language in some way. These types of mistakes are called syntax errors. • The translator produces descriptive error messages. For example, if you mistakenly write N=2 *(I+J))-which has two closing parentheses instead of one-you will get a message that says, "UNMATCHED PARENTHESES.“ 16
  • 17. Five main steps in programming process • Programs are most commonly translated by a compiler. A compiler translates your entire program at one time. The translation involves your original program, called a source module, which is transformed by a compiler into an object module. • Prewritten programs from a system library may be added during the link/load phase, which results in a load module. The load module can then be executed by the computer. • Debugging. A term used extensively in programming, debugging means detecting, locating, and correcting bugs (mistakes), usually by running the program. These bugs are logic errors, such as telling a computer to repeat an operation but not telling it how to stop repeating. In this phase you run the program using test data that you devise. You must plan the test data carefully to make sure you test every part of the program. 17
  • 18. Five main steps in programming process 5. Documenting the Program: Documentation is a written detailed description of the programming cycle and specific facts about the program. Typical program documentation materials include the origin and nature of the problem, a brief narrative description of the program, logic tools such as flowcharts and pseudocode, data-record descriptions, program listings, and testing results. Comments in the program itself are also considered an essential part of documentation. 18
  • 19. Computer Programming Constructs/Control Constructs Structured Programming Constructs: 1. Sequence Control Structure (Sequence Logic or Sequential Flow). 2. Selection Control Structure (Selection Logic or Conditional Flow). 3. Repetition Control Structure (Iteration Logic or Repetitive Flow). 1. Sequence Control Structure (Sequence Logic or Sequential Flow): If nothing is specified then the modules are executed in the sequence in which they are written. Thus in it the modules are executed one after the other. The sequence control structure is shown below: Algorithm . . . Module A Module B Module C . . 19
  • 20. 2. Selection Control Structure (Selection Logic or Conditional Flow): In it there are various conditions on the basis of which one module is selected out of several given modules. The structures which implement this logic are called conditional structures. The conditional structures can be divided into following categories: 1. Single Alternative: This structure has the following form: If condition, then [Module A] [End of If structure] 20
  • 21. According to this if the condition is true then module A is executed. Otherwise, module A is skipped. Its flowchart is: 2. Double Alternative: This structure has the following form: If condition, then [Module A] Else [Module B] [End of If structure] According to this if the condition is true then module A is executed. Otherwise, module B is executed. 21 Single Alternative(cont.)
  • 22. 3. Multiple Alternative: This structure has the following form: If condition (1), then [Module A1] Else If condition (2), then [Module A2] . . . Else If condition (n), then [Module An] Else [Module B] [End of If structure] 22
  • 23. Multiple Alternative (cont.) According to this only one of the modules will be executed. If condition 1 is true then module A1 will be executed. Otherwise condition 2 will be checked. If condition 2 is true then module A2 will be executed. And so on. If none of the conditions is true then module B will be executed. Its flowchart is: 23
  • 24. 4. Repetition Control Structure (Iteration Logic or Repetitive Flow): In this structure, loops are implemented. Loop is used to implement those statements which are to be repeated again and again until some condition is satisfied. It implements while and for loops. Each of these begin with Repeat statement. For example is case of Repeat- while structure: Repeat steps 1 to n while condition: [Steps] [End of Repeat-while structure] Its flowchart is: 24
  • 25. 25 Programming Languages Machine Language Assembly Language High-Level Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010
  • 26. 26 Programming Languages Machine Language Assembly Language High-Level Language Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3 … ADDF3 R1, R2, R3 … Assembly Source File Assembler … 1101101010011010 … Machine Code File
  • 27. 27 Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415;
  • 28. 28 Popular High-Level Languages •COBOL (COmmon Business Oriented Language) •FORTRAN (FORmula TRANslation) •BASIC (Beginner All-purpose Symbolic Instructional Code) •Pascal (named for Blaise Pascal) •Ada (named for Ada Lovelace) •C (whose developer designed B first) •Visual Basic (Basic-like visual language developed by Microsoft) •Delphi (Pascal-like visual language developed by Borland) •C++ (an object-oriented language, based on C) •C# (a Python-like language developed by Microsoft) •Python (We use it in the book)
  • 29. Programming Languages • High level programming languages: is languages program than use languages or syntax which closes to human languages so; it is easy to understanding the languages. This type of language is machine- independent, and uses similar language as English, which is easily understandable by human. Types of high level languages are: 1) Procedural Languages 2) Functional & Non procedural Languages 3) Object Oriented Languages 29
  • 30. Levels of Programming Languages High-level program class Triangle { ... float surface() return b*h/2; } Low-level program LOAD r1,b LOAD r2,h MUL r1,r2 DIV r1,#2 RET Executable Machine code 0001001001000101001001 001110110010101101001. .. 30
  • 31. Procedural programming languages • Procedural language is a type of computer programming language that specifies a series of well-structured steps and procedures within its programming context to compose a program. It contains a systematic order of statements, functions and commands to complete a computational task or program. • Procedural language is also known as imperative language. • Procedural languages are: • C/C++ Language • FORTRAN (FORmula TRANslation) • BASIC (Beginners All Purpose Symbolic Instruction Code) • COBOL (Common Business Oriented Language) These types of languages are “Third-Generation Language”. 31
  • 32. Non Procedural Languages • In non-procedural languages the computer is not limited to a set of precise instructions. Instead, the programmer defines only the problem—not the instructions--to solve the problem. Non Procedural Programming Languages are: • SQL (Structured Query Language) • LISP (List Processing) • PROLOG (PROgramming with LOGic) 32
  • 33. Object Oriented Programming • Object-oriented programming (OOP) is an engineering approach for building software systems • Based on the concepts of classes and objects that are used for modeling the real world entities • A program models a world of interacting objects • Objects create other objects and “send messages” to each other (in Java, call each other’s methods) • Each object belongs to a class • A class defines properties of its objects • The data type of an object is its class • Programmers write classes (and reuse existing classes) • All modern languages are object-oriented: Java, C#, PHP (Hypertext Preprocessor), Perl (Practical Extraction and Reporting Language), C++, ... 33
  • 34. Compiling Source Code A program written in a high-level language is called a source program. Since a computer cannot understand a source program. Program called a compiler is used to translate the source program into a machine language program called an object program. The object program is often then linked with other supporting library code before the object can be executed on the machine. Compiler Source File Machine-language File Linker Executable File Library Code 34
  • 35. Operating Systems The operating system (OS) is a program that manages and controls a computer’s activities. You are probably using Windows 98, NT, 2000, XP, or ME Etc. Windows is currently the most popular PC operating system. Application programs such as an Internet browser and a word processor cannot run without an operating system. User Application Programs Operating System Hardware 35
  • 36. 36 What is Python? General Purpose Interpreted Object-Oriented Python is a general purpose programming language. That means you can use Python to write code for any programming tasks. Python are now used in Google search engine, in mission critical projects in NASA, in processing financial transactions at New York Stock Exchange.
  • 37. 37 What is Python? General Purpose Interpreted Object-Oriented Python is interpreted, which means that python code is translated and executed by an interpreter one statement at a time. In a compiled language, the entire source code is compiled and then executed altogether.
  • 38. 38 What is Python? General Purpose Interpreted Object-Oriented Python is an object-oriented programming language. Data in Python are objects created from classes. A class is essentially a type that defines the objects of the same kind with properties and methods for manipulating objects. Object-oriented programming is a powerful tool for developing reusable software.
  • 39. 39 Python’s History • created by Guido van Rossum in Netherlands in 1990 • Open source Python 2 vs. Python 3 Python 3 is a newer version, but it is not backward compatible with Python 2. That means if you write a program using Python 2, it may not work on Python 3.
  • 43. 43 A Simple Python Program # Display two messages print("Welcome to Python") print("Python is fun") Run Welcome Listing 1.1 IMPORTANT NOTE: (1) To enable the buttons, you must download the entire slide file slide.zip and unzip the files into a directory (e.g., c:slide). (2) You must have installed Python and set python bin directory in the environment path. (3) If you are using Office 2010, check PowerPoint2010.doc located in the same folder with this ppt file.
  • 44. 44 Creating and Editing Using Notepad To use Notepad, type notepad Welcome.py from the DOS prompt.
  • 45. 45 # Display two messages print("Welcome to Python") print("Python is fun") Trace a Program Execution Execute a statement
  • 46. 46 # Display two messages print("Welcome to Python") print("Python is fun") Trace a Program Execution Execute a statement
  • 47. 47 Anatomy of a Python Program • Statements • Comments • Indentation
  • 48. 48 # Display two messages print("Welcome to Python") print("Python is fun") Statement A statement represents an action or a sequence of actions. The statement print("Welcome to Python") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Python“.
  • 49. 49 # Display two messages print("Welcome to Python") print("Python is fun") Indentation The indentation matters in Python. Note that the statements are entered from the first column in the new line. It would cause an error if the program is typed as follows:
  • 50. 50 Special Symbols Character Name Description () # " " ''' ''' Opening and closing parentheses Pound sign Opening and closing quotation marks Opening and closing quotation marks Used with functions. Precedes a comment line. Enclosing a string (i.e., sequence of characters). Enclosing a paragraph comment.
  • 51. 51 Programming Style and Documentation • Appropriate Comments • Proper Indentation and Spacing Lines
  • 52. 52 Appropriate Comments Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Include your name, class section, instructor, date, and a brief description at the beginning of the program.
  • 53. 53 Proper Indentation and Spacing • Indentation • Indent four spaces. • A consistent spacing style makes programs clear and easy to read, debug, and maintain. • Spacing • Use blank line to separate segments of the code.
  • 54. 54 Programming Errors • Syntax Errors • Error in code construction • Runtime Errors • Causes the program to abort • Logic Errors • Produces incorrect result