Chapter 4 - Intro To Programming and Python
Chapter 4 - Intro To Programming and Python
CHAPTER 4
INTRODUCTION TO PROGRAMMING
AND PYTHON
CONTENTS
2. Programming Language
3. Introduction to Python
Introduction to CSE 2
1. Programs and Programming
• This course is about programming and computational thinking, not
about learning a programming language
• Once you learnt programming in one language, it is relatively easy to
learn another language, such as C++, Java,…
• What is programming?
• Programming is writing computer code to create a program, to solve
a problem.
• Programming is the translation of algorithm into a program to tell a
computer exactly what to do and how to do.
• Why learn programming?
• Programming gives you the ability to digitize your ideas.
• It is the important skill for your job
Introduction to CSE 3
What is a program?
• A program is a sequence of instructions that performs a specific
task when executed by a computer.
• A program implements an algorithm.
• Program created by a programmer using a programming language.
Introduction to CSE 5
What is debugging?
Introduction to CSE 6
2. Programming Language
• An language used to create
programs.
• Have a set of keywords, syntax,
rules for instructing a computer to
perform specific tasks.
• The most popular languages are:
Python, Java, Javascript, C/C++,…
• Levels of Language
• Depending on how close they are to
the language the computer itself
uses (0s and 1s = low) or to the
language people use.
Introduction to CSE 7
Generation of programming languages
Intelligent
Languages
Non-procedural 5GL
Procedural Languages
Languages 4GL
Assembly 3GL
Language
2GL
Machine
Language
1GL
Introduction to CSE 8
Levels: Overview
Introduction to CSE 9
1GL: Machine Language
• The only language that the computer directly understands.
• Represents data and program instructions as 1s and Os-binary digits.
• Each type of computer has its own machine language.
→A computer could not understand programs written in another machine
language.
• Advantages:
• The code can run very fast and efficiently, since it is directly executed
by the CPU
• Disadvantages:
• Difficult to read, write, and edit if errors occur.
• Hardware-dependent programming language
• Not portable.
Introduction to CSE 10
1GL: Machine Language
Introduction to CSE 11
2GL: Assembly Language
• Is a symbolic language that use symbols to represent machine-
language instructions.
• An assembly language statement consists of a label, an operation
code, and one or more operands.
• Closely connected to machine language and the internal architecture
of the computer system.
• A source program written in assembly language need a translator
often known as the assembler to convert them into machine
language.
Introduction to CSE 12
2GL: Assembly Language
• Example: Assembly Language program to add two numbers.
• Advantages:
• Efficient in terms of execution time and main memory usage
• Disadvantages:
• Machine-dependent → less portable
Introduction to CSE 13
3GL: Procedural Languages
• The program statements are not closely related to the internal
characteristics of the computer and is referred to high-level
languages.
• Resembles natural/human languages.
• A translator is needed to translate the instructions
written in high level language into machine language.
• Interpreter
• Compiler
Introduction to CSE 14
3GL: Procedural Languages
• Some procedural languages: Pascal, C/C++, C#, Java, Cobol,…
• Advantages:
• Portable
• Easy to read, write, debug → the programmer has more time to
think about overall program logic.
• Disadvantages:
• Require translator → slow execution.
• Example: C program to add two numbers
int a, b, c;
a = 83;
b = -2;
c = a + b;
Introduction to CSE 15
4GL: Non-procedural Languages
• Very High-Level Languages
• Programmers define only what they want the computer to do,
without supplying all the details of how it has to be done.
• The code is written in English-like sentences.
• Example of a 4GL is the query language that allows a user to
request information from a database.
• Advantages:
• Code is easier to maintain
• Enhances the productivity of the programmers as they have to type
fewer lines of code to get something done.
• A minimum of training by both programmers and non-programmers
• Disadvantages:
• Do not make efficient use of machine’s resources.
Introduction to CSE 16
4GL: Non-procedural Languages
• Examples of Non-Procedural Languages:
• SQL, QBE, Intellect,…
Introduction to CSE 17
5GL: Non-procedural Languages
• 5GLs are centered on solving problems using constraints given to
the program, rather than using an algorithm written by a
programmer.
• They are widely used in artificial intelligence research.
• Knowledge-based languages.
• Examples of a 5GL: Prolog, OPS5, and Mercury.
• Resembles to the "natural“ language.
Introduction to CSE 18
Choosing a Language
Introduction to CSE 19
3. Introduction to Python
Introduction to CSE 20
The History of Python
History Python was created by Guido van Rossum in the
of Netherlands in 1990
Python
Simple, concise, and intuitive syntax and extensive library
Introduction to CSE 21
Environments
Introduction to CSE 22
Q&A
Introduction to CSE 23