SlideShare una empresa de Scribd logo
1 de 54
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

Más contenido relacionado

Similar a Programming_Lecture_1.pptx

Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
Prof. Erwin Globio
 
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
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
Hattori Sidek
 

Similar a 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++
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
 
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
 

Último

Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
gajnagarg
 
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
amitlee9823
 
How to Build a Simple Shopify Website
How to Build a Simple Shopify WebsiteHow to Build a Simple Shopify Website
How to Build a Simple Shopify Website
mark11275
 
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
amitlee9823
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
gajnagarg
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion pills in Kuwait Cytotec pills in Kuwait
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
nirzagarg
 
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
amitlee9823
 

Último (20)

VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfJordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
 
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️9352988975 Two shot with one girl (...
 
Gamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad IbrahimGamestore case study UI UX by Amgad Ibrahim
Gamestore case study UI UX by Amgad Ibrahim
 
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
Vip Mumbai Call Girls Borivali Call On 9920725232 With Body to body massage w...
 
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 105, Noida Call girls :8448380779 Model Escorts | 100% verified
 
How to Build a Simple Shopify Website
How to Build a Simple Shopify WebsiteHow to Build a Simple Shopify Website
How to Build a Simple Shopify Website
 
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men  🔝jhansi🔝   Escorts S...
➥🔝 7737669865 🔝▻ jhansi Call-girls in Women Seeking Men 🔝jhansi🔝 Escorts S...
 
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
Just Call Vip call girls dharamshala Escorts ☎️9352988975 Two shot with one g...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
 
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
❤Personal Whatsapp Number 8617697112 Samba Call Girls 💦✅.
 
Just Call Vip call girls Nagpur Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Nagpur Escorts ☎️8617370543 Starting From 5K to 25K ...Just Call Vip call girls Nagpur Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Nagpur Escorts ☎️8617370543 Starting From 5K to 25K ...
 
Lecture 01 Introduction To Multimedia.pptx
Lecture 01 Introduction To Multimedia.pptxLecture 01 Introduction To Multimedia.pptx
Lecture 01 Introduction To Multimedia.pptx
 
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️call girls in Dakshinpuri  (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
call girls in Dakshinpuri (DELHI) 🔝 >༒9953056974 🔝 genuine Escort Service 🔝✔️✔️
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024The hottest UI and UX Design Trends 2024
The hottest UI and UX Design Trends 2024
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
 

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