Untitled

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

1.

Computer Organization
2. Machine Languages, Assembly Languages,
and High-Level Languages
3. Programming, Programming Language, Computer programmer,
Syntax
4. Program Components
5. Introduction to Python

2
Ø A computer consists of:
o Hardware: Physical devices of computer system
o Software: Programs that run on computers
§ A program is a set of instructions written in a high programming language
(such as C/C++, Java, Python, …) to do a specific task.

Central Processing Unit

Control Unit

Input device Output Device

Arithmetic/Logic Unit

Memory Unit My data My Progam

3
Ø The main components of a computer system are:

1. Input unit (mouse, keyboard)

2. Output unit (printer, monitor, audio speakers)

3. Memory unit (retains input data, calculated data and instructions)

4. Central processing unit (CPU) which consists of:


4.1 Control unit (supervises the operation of other devices)
4.2 Arithmetic and Logic unit (ALU) (performs calculations)

5. Secondary storage (hard drives, floppy drives)


4
} Programmers write instructions in various programming
languages, some directly understandable by computers and others
requiring intermediate translation steps.

} These may be divided into three general types:


◦ Machine languages
◦ Assembly languages
◦ High-level languages

5
1- Machine language (Language of Computer)
} Any computer can directly understand only its own machine
language, defined by its hardware design.
◦ Generally consist of strings of numbers (1s and 0s) that instruct computers to
perform their most elementary operations one at a time.
◦ Machine dependent—a particular ma-chine language can be used on only
one type of computer.
– To calculate wages= rates * hours in machine language
} 100100 010001 //load
} 100110 010010 // multiply
} 100010 010011 // store
Binary digit (bit): The digit 0 or 1
Binary code: A sequence of 0s and 1s
Byte: A sequence of eight bits.
} Difficult and tiring for humans.

6
} 2- Assembly language
English-like abbreviations that represent elementary operations formed the basis of
assembly languages.
Translator program Assembler: Translates a program written in assembly
language into machine language.
– Example
– load basepay
add overpay Assembly Language Machine language
store grosspay LOAD 100100
STOR 100010
MULT 100110
ADD 100101
SUB 100011

Examples of instructions in Assembly


Language and Machine Language
7
} 3- High-level language
◦ Single statements accomplish substantial tasks.
◦ Compilers convert high-level language programs into machine
language.
◦ Allow you to write instructions that look almost like everyday
English and contain commonly used mathematical notations.
◦ A payroll program written in a high-level language might contain
a single statement such as
– grossPay = basePay + overTimePay

} Compiling a high-level language program into machine language


can take a considerable amount of computer time.

} Interpreter programs execute high-level language programs directly,


although slower than compiled programs run.
8
} Programming:
Is a process of problem solving.
} Programming Language:
A set of rules, symbols and special words used to write computer program.
Ø Syntax:
Rules that specify which statements (instructions) are legal.
Ø Computer programmer:
A programmer, computer programmer, developer,
coder, or software engineer is a person who
writes computer software.

9
Ø A program consists of the following:
o Input: Data to begin with to solve the program.
o Output: The target of the problem. This is the expected result.
§ Nouns in the problem statement suggest input and output data.
o Processing: This is the set of instructions that drive from the
input to the output.
§ Verbs in the problem suggest the processing steps.

Output
Input Data Processing
Data

10
Write a program that calculates the area and the perimeter of a rectangle
of width and length 5 cm and 3 cm respectively.
Ø Input
Width = 5 cm
Length = 3 cm
Ø Output
Area = ?
Perimeter = ?
Ø Processing (Input à Output)
Area = length*width = 5 * 3 = 15 cm2
Perimeter = 2*( length + width) = 2*(3 + 5) = 16 cm

If the values of the input data are not given in the problem statement, they
may be read from the user through the keyboard.

11
Calculate the area and the perimeter of a circle of radius = 2.5 cm.

Ø Input
Radius = 2.5 cm
PI = 3.14
Ø Output
Area = ?
Perimeter = ?
Ø Processing (Input à Output)
Area = PI * Radius * Radius = 3.14*6.25 = 19.625 cm2
Perimeter = 2 * PI * Radius = 2*3.14*2.5 = 15.7 cm

If the values of the input data are not given in the problem statement, they
may be read from the user through the keyboard.

12
Calculate the sum and the average of the numbers 10, 20, 30, 40 and 50.

Ø Input
Five numbers = x1, x2, x3, x4, x5
Ø Output
Sum = ?
Average = ?
Ø Processing (Input à Output)
Sum = x1+x2+x3+x4+x5 =10+20+30+40+50= 150
Average = Sum/5 = 150/5 = 30

If the values of the input data are not given in the problem statement, they
may be read from the user through the keyboard.

13
§ Python is a Programming language, so the primary purpose
of Python is Software Development.

§ Python was created by Guido Van Rossum in 1989, but


publicly released in 1991, It is further developed by the
Python Software Foundation, and Python official website is
(python.org).

14
§ Python is not named after the snake Python, The father of Python – Guido Van
Rossum said the name of the language was taken from the British sketch comedy
series “Monty Python’s Flying Circus” from 1969-1974

15
} general-purpose language } It has a simple syntax
} high-level language } It has powerful set of libraries
} Interpreted language } Automatic memory management
} Interactive } It’s free (open source)!
} it is easy for beginners to learn.
} Object oriented language
} it is widely used in many scientific
} Independent from platforms
areas for data exploration.
} Focused on development time

16
q Python is a general-purpose language – It is a programming language designed to be
used for writing software in the widest variety of application domains.

q Python is a high-level language – It is a programming language designed to simplify


computer programming, high-level source code contains easy-to-read syntax that is
later converted into a low-level language, which can be recognized and run by a
specific CPU.

q Python works on different platforms (Windows, Mac, Linux, etc).

q Python has a simple syntax similar to the English language.

17
qPython is an interpreted language – An interpreted language is a type of programming
language for which most of its implementations execute instructions directly and freely,
without previously compiling a program into machine-language instructions.

qPython is interactive – Python supports Interactive mode Programming, It provides us


with a quick way of running blocks or a single line of Python code.

qPython is object-oriented – It is an object-oriented programming language and it also


supports functional programming. It allows us to develop applications using an Object-
Oriented approach. In Python, we can easily create and use classes and objects.

18
qPython is open source – Python is developed under an OSI-approved open source
license, making it freely usable and distributable, even for commercial use. Python’s
license is administered by the Python Software Foundation.
OSI (Open Systems Interconnection) is a reference model for how applications
communicate over a network.

19
} The Python Interpreter is a program that can read Python programming statements and
execute them is the Python interpreter.
} Python interpreter has two modes:

–Interactive mode waits for a statement from the keyboard and executes it.
–Script mode reads the contents of a file (Python programmer Python script) and
interprets each statement in the file

20
Python is simple but yet powerful and is a good tool for rapid-prototyping programming
Hence, we can focus less on the language but more on problem solving

21
22
} Python is used to develop:
} 1. Desktop GUI (Graphical User Interface)
2. Web and Internet Development (IoT – Internet of Things)
3. Games and 3D Graphics
4. Scientific and Numeric Applications.
5. Machine Learning and Artificial Intelligence.
} Machine Learning Is a Form of Artificial Intelligence that Makes Predictions
from Data. See How Machine Learning Can Learn from Data

23
} Python is used to develop:
6. Data Science and Data Visualization.
7. Enterprise Applications (Such as e-commerce, ERP, etc.)
} Enterprise resource planning (ERP) refers to a type of software that organizations
use to manage day-to-day business activities such as accounting, procurement,
project management, risk management and compliance, and supply chain
operations

24
} Python is used to develop:
8. Network Programming
9. Embedded Applications
} An embedded application is software that is placed permanently inside some
kind of device to perform a very specific set of functions. Some small
embedded applications like those in a microwave oven do not need an operating
system (OS) to control them.

25
} Python is used to develop:
10. Audio and Video Applications
11. Learning/Education Applications
12. CAD (Computer-Aided Designing) Applications
13. Software Testing / Writing automated tests

26
} The Python package includes the Python interpreter and runtime
libraries as one would expect, but it also includes several useful
utilities:
◦ Module Docs (Pydoc):
– The Python package differs depending on the operating
system, but most commonly the package will include Pydoc,
the Python documentation tool.
– This tool is a small search utility that will locate items in the
Python documentation.
◦ Python Manuals (Pyhelp):
– Also found in the program menu is an option, Python
Manuals, that brings up the Python documentation in a
Windows help file format,

27
◦ Python (command line):
– Python is an interpreted language, which means code is
not compiled into an executable file; it is just interpreted
on the fly in real time.
– That real time nature includes the Python command
prompt, which can accept Python commands one line at a
time.
◦ IDLE (Python GUI):
– IDLE is a text editor and simple development environment
for Python programming.

28
} The programmers of big companies use Python as it has created a mark for itself in
the software development with characteristic features like:
ü Interactive
ü Interpreted
ü Modular
ü Dynamic
ü Object-oriented
ü Portable
ü High level
ü Extensible in C++ & C

29
} The programmers of big companies use Python as it has created a mark for itself
in the software development with characteristic features like:
ü Easy-to-learn
ü Easy-to-read
ü Easy-to-maintain
ü Robust
ü Effective as a Rapid Prototyping Tool
ü A Memory Manager
ü Interpreted and (Byte-) Compiled

30
31
32
q Vocabulary / Words - Variables and Reserved words.
• Sentence structure - valid syntax patterns
• Story structure - constructing a program for a purpose

33
◦ IDLE is Python’s Integrated Development and Learning Environment.
◦ Comes with many standard Python installs.
◦ Support indentation.(useful for beginners learning about Python's indentation).
◦ Coded in 100% Python
◦ Cross - Platform: works on Windows/Linux/ Unix

34
} In the next few chapters, we will learn more about the vocabulary, sentence structure, paragraph
structure, and story structure of Python. We will learn about the powerful capabilities of Python and how
to compose those capabilities together to create useful programs.

} There are some low-level conceptual patterns that we use to construct programs. These constructs are
not just for Python programs, they are part of every programming language from machine language up
to the high-level languages.

} input Get data from the “outside world”. This might be reading data from a file, or even some kind of
sensor like a microphone or GPS. In our initial programs, our input will come from the user typing data
on the keyboard. output Display the results of the program on a screen or store them in a file or perhaps
write them to a device like a speaker to play music or speak text. sequential execution Perform
statements one after another in the order they are encountered in the script. conditional execution Check
for certain conditions and then execute or skip a sequence of statements. repeated execution Perform
some set of statements repeatedly, usually with some variation. reuse Write a set of instructions once and
give them a name and then reuse those instructions as needed throughout your program.

35

You might also like