0% found this document useful (0 votes)
2 views

Chapter 1 Python

The document is a comprehensive course outline on Computer Programming by Eyob S. at AAiT, detailing various chapters covering topics such as computation, programming constructs, data structures, and object-oriented programming. It includes a historical overview of computing, the evolution of computer generations, and teaching methods. The course emphasizes practical applications through laboratory work, projects, and exams.

Uploaded by

Masterr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 1 Python

The document is a comprehensive course outline on Computer Programming by Eyob S. at AAiT, detailing various chapters covering topics such as computation, programming constructs, data structures, and object-oriented programming. It includes a historical overview of computing, the evolution of computer generations, and teaching methods. The course emphasizes practical applications through laboratory work, projects, and exams.

Uploaded by

Masterr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Computer Programming

Eyob S.

AAiT

May , 2024

Eyob S. (AAiT) Computer Programming May , 2024 1 / 62


Presentation Overview

1 Course Outline

2 Chapter 1: Introduction
Introduction
Computation
History of computing and programming
Generations of Computers
Structure of a basic Computer System
Classification of Computers by Size

3 Programming Constructs

4 Programming Language

Eyob S. (AAiT) Computer Programming May , 2024 2 / 62


Course Outline

Course Outline

Eyob S. (AAiT) Computer Programming May , 2024 3 / 62


Chapter 1: Introduction

What is computation?

History of computing and programming

Formal and Natural languages

Eyob S. (AAiT) Computer Programming May , 2024 4 / 62


Chapter 2: Variables, Expressions and Statements

Primitive data types and values

Variables

Data Types & Casting

Booleans and Expressions

Eyob S. (AAiT) Computer Programming May , 2024 5 / 62


Chapter 3: Functions 1

What are functions?

Built-in Functions

Function calls

Parameters and Arguments

Flow of execution

Function composition

Eyob S. (AAiT) Computer Programming May , 2024 6 / 62


Chapter 4: Conditionals

Boolean Expression and Logical Operators

Conditional Execution

Chained and Nested Conditions

Keyboard input and Defensive Programming

Eyob S. (AAiT) Computer Programming May , 2024 7 / 62


Chapter 5: Functions 2

User-Defined Functions

Fruitful and void functions

Return vs Print

Function Scope

Decomposition and Abstractions

Eyob S. (AAiT) Computer Programming May , 2024 8 / 62


Chapter 6: Iteration

Looping Basics

The while loop

Break and Continue

For Loops, Nested Loops

Nested Lists & Looping

Eyob S. (AAiT) Computer Programming May , 2024 9 / 62


Chapter 7: Strings

String as a sequence

Indexing

Mutability and Immutability

Searching

String Comparison

Eyob S. (AAiT) Computer Programming May , 2024 10 / 62


Chapter 8: Data Structures

What are Data Structures

Lists

Numerical Indexing

Dictionaries

Tuples and Sets

Eyob S. (AAiT) Computer Programming May , 2024 11 / 62


Chapter 9: Persistence

File

Reading and Writing

Common file formats

Pickling

Eyob S. (AAiT) Computer Programming May , 2024 12 / 62


Chapter 10: Object Oriented Programming

Class and Object

Object Modelling

Eyob S. (AAiT) Computer Programming May , 2024 13 / 62


Teaching Methods: Lecture supported by Laboratory

Lab........................... 20%

Project...................... 20%

Test/quiz................... 10%

Assignments............... 20%

Final Exam................. 30%

Eyob S. (AAiT) Computer Programming May , 2024 14 / 62


Chapter 1

Introduction

Eyob S. (AAiT) Computer Programming May , 2024 15 / 62


What is Computer?

a programmable electronic device designed to accept data (input), store

the data as necessary (storage), perform prescribed mathematical and

logical operations at high speed (processing), and display the results of

these operations (output). (dictionary.com)

Eyob S. (AAiT) Computer Programming May , 2024 16 / 62


What is Computer Science?

“Computer Science is no more about computers than astronomy is

about telescopes” Edsger Dijkstra (1930 - 2002)

is Computer Science the study of computers? is Computer Science the

study of how to write computer programs?

there are theoretical works in CS, which do not make use of real com-

puters: even the early work in CS took place before the development

of the first computer

Eyob S. (AAiT) Computer Programming May , 2024 17 / 62


Computer Science

the science that deals with the theory and methods of processing in-

formation in digital computers, the design of computer hardware and

software, and the applications of computers. (www.dictionary.com)

computer science, the study of computers and computing, including

their theoretical and algorithmic foundations, hardware and software,

and their uses for processing information. (britannica.com)

Eyob S. (AAiT) Computer Programming May , 2024 18 / 62


Computation

What is Computation?

Eyob S. (AAiT) Computer Programming May , 2024 19 / 62


What is Computation?

the act or process of calculating an answer or amount by using a ma-

chine (www.dictionary.com)

a calculation involving numbers or quantities (collinsdictionary.com)

Computation is any type of calculation that includes both arithmetical

and non-arithmetical steps and which follows a well-defined model (e.g.

an algorithm). (en.wikipedia.org)

Eyob S. (AAiT) Computer Programming May , 2024 20 / 62


What is Computation?

A calculation is a deliberate process that transforms one or more inputs

into one or more results. (en.wikipedia.org)

The term is used in a variety of senses, from the very definite arith-

metical calculation of using an algorithm, to the vague heuristics of

calculating a strategy in a competition, or calculating the chance of a

successful relationship between two people. (en.wikipedia.org)

Eyob S. (AAiT) Computer Programming May , 2024 21 / 62


What is Computation?

Computer science studies computation: investigates problems that can

be solved computationally, uses programming languages to describe

computations,

Computer science studies machines that carry out computations, the-

oretical limits of computation (what is or is not computable), com-

putational solutions to problems in math, science, medicine, business,

education etc

Eyob S. (AAiT) Computer Programming May , 2024 22 / 62


History

History of computing and programming

Eyob S. (AAiT) Computer Programming May , 2024 23 / 62


History of computing and programming

The earliest known calculating device is probably the abacus. The aba-

cus is a digital device; that is, it represents values discretely. A bead

is either in one predefined position or another, representing unambigu-

ously, say, one or zero.

Figure: Abacus

Eyob S. (AAiT) Computer Programming May , 2024 24 / 62


History of computing and programming

Calculating devices took a different turn when John Napier, a Scottish

mathematician, published his discovery of logarithms in 1614.

The first calculator or adding machine to be produced in any quantity

and actually used was the Pascaline, or Arithmetic Machine, designed

and built by the French mathematician-philosopher Blaise Pascal be-

tween 1642 and 1644.

Eyob S. (AAiT) Computer Programming May , 2024 25 / 62


History of computing and programming

Charles Babbage (1791-1871), computer pioneer, designed two classes

of engine, Difference Engines, and Analytical Engines.

Difference engines are strictly calculators. They crunch numbers the

only way they know how - by repeated addition according to the method

of finite differences.

The Analytical Engine was to be a general-purpose, fully program con-

trolled, automatic mechanical digital computer.

Eyob S. (AAiT) Computer Programming May , 2024 26 / 62


History of computing and programming

Eyob S. (AAiT) Computer Programming May , 2024 27 / 62


History of computing and programming

Ada Lovelace (1815-1852), En-

glish mathematician, an associate of

Charles Babbage, for whose proto-

type of a digital computer she cre-

ated a program. She has been called

the first computer programmer.

Eyob S. (AAiT) Computer Programming May , 2024 28 / 62


History of computing and programming

Alan Turing played a crucial role

in cracking intercepted coded mes-

sages of Enigma machine by devising

an electro-mechanical machine called

the bombe.

Eyob S. (AAiT) Computer Programming May , 2024 29 / 62


History of computing and programming

A program is a set of instructions written in a particular programming

language to solve a problem

An algorithm is a sequence of unambiguous steps to be followed to

solve a problem

Eyob S. (AAiT) Computer Programming May , 2024 30 / 62


History of computing and programming

Eyob S. (AAiT) Computer Programming May , 2024 31 / 62


Fixed program & Stored-program Computers

A stored-program digital computer keeps both program instructions

and data in read–write, random-access memory (RAM).

Changing the program of a fixed-program machine requires rewiring,

restructuring, or redesigning the machine.

Eyob S. (AAiT) Computer Programming May , 2024 32 / 62


Generations of Computers

Generations of Computers

Eyob S. (AAiT) Computer Programming May , 2024 33 / 62


1940 – 1956: (First Generation – Vacuum Tubes )

These early computers used vacuum tubes as circuitry and magnetic


drums for memory. These first generation computers relied on machine
language.

These computers were limited to solving one problem at a time. Input


was based on punched cards and paper tape. Output came out on
print-outs.

The two notable machines of this era were the UNIVAC and ENIAC
machines – the UNIVAC is the first commercial computer which was
purchased in 1951 by a business – the US Census Bureau.

Eyob S. (AAiT) Computer Programming May , 2024 34 / 62


1940 – 1956: (First Generation – Vacuum Tubes )

Eyob S. (AAiT) Computer Programming May , 2024 35 / 62


1940 – 1956: (First Generation – Vacuum Tubes )

Figure: left:ENIAC, right:UNIVAC

Eyob S. (AAiT) Computer Programming May , 2024 36 / 62


1956 – 1963: (Second Generation – Transistors)

The language evolved from cryptic binary language to symbolic (‘as-


sembly’) languages. About the same time high level programming
languages were being developed (early versions of COBOL and FOR-
TRAN).

Transistor-driven machines were the first computers to store instruc-


tions into their memories – moving from magnetic drum to magnetic
core ‘technology’.

The early versions of these machines were developed for the atomic
energy industry.

Eyob S. (AAiT) Computer Programming May , 2024 37 / 62


1964 – 1971: (Third Generation – Integrated Circuits)

By this phase, transistors were now being miniaturised and put on

silicon chips (called semiconductors).

This led to a massive increase in speed and efficiency of these machines.

These were the first computers where users interacted using keyboards

and monitors which interfaced with an operating system

Eyob S. (AAiT) Computer Programming May , 2024 38 / 62


1972 – 2010: (Fourth Generation – Microprocessors)

In the third-generation, different circuits were present on different ICs.


Finally, all these different circuits were made on a single IC called the
microprocessor.

Intel developed the Intel 4004 chip in 1971, which positioned all com-
puter components (CPU, memory, input/output controls) onto a single
chip.

Other major advances during this period have been the Graphical user
interface (GUI), the mouse and more recently the astounding advances
in lap-top capability and hand-held devices.

Eyob S. (AAiT) Computer Programming May , 2024 39 / 62


Transistors, ICs, and MPs

Eyob S. (AAiT) Computer Programming May , 2024 40 / 62


2010. . . : (Fifth Generation – Artificial Intelligence)

Computer devices with artificial intelligence are still in development

AI is a reality made possible by using parallel processing and supercon-


ductors. Leaning to the future, computers will be radically transformed
again by Quantum Computation, Molecular and Nano Technology.

The essence of fifth generation will be using these technologies to ul-


timately create machines which can process and respond to natural
language, and have capability to learn and organise themselves.

Eyob S. (AAiT) Computer Programming May , 2024 41 / 62


AI

Eyob S. (AAiT) Computer Programming May , 2024 42 / 62


Structure of a basic Computer System

Structure of a basic Computer System

Eyob S. (AAiT) Computer Programming May , 2024 43 / 62


System

The word ‘system’ is used to describe any organization or device that


includes three features: Input, Output, and process.

Often there are many inputs and outputs. Some of the outputs are
required and some are waste products. To a greater or lesser extent,
all processes generate some waste heat.

Eyob S. (AAiT) Computer Programming May , 2024 44 / 62


Internal organization of computers

The internal working of every computer can be broken down into


three parts:
CPU(central processing unit), memory, and I/O (input/output) devices.

The function of CPU is to execute (process) information stored in


memory whereas the function of I/O devices such as the keyboard and
video monitor is to provide a means of communicating with the CPU.

The CPU is connected to memory and I/O through strips of wire


called a bus.

Eyob S. (AAiT) Computer Programming May , 2024 45 / 62


Internal organization of computers

Eyob S. (AAiT) Computer Programming May , 2024 46 / 62


Classification of Computers by Size

Classification of Computers by Size

Eyob S. (AAiT) Computer Programming May , 2024 47 / 62


Supercomputers

These are arguably the most powerful in terms of speed and accu-
racy. They are useful in problems that require complex mathematical
computations.
They are capable of executing trillions of instructions per second, which
is calculated in floating point operations per second (FLOPS). They
also don’t come cheap as they can be priced between 200, 000 to over
100 million.

Eyob S. (AAiT) Computer Programming May , 2024 48 / 62


Mainframes

Mainframe computers are large and powerful machines. However, they


fall short in terms of the computation ability seen in supercomputers.
They are like big file servers, enabling multiple users from nearby and
remote locations to access resources at the same time.
Users access the mainframe using terminals or personal computers.
This can happen within the same building or via wide area network
(WAN).

Eyob S. (AAiT) Computer Programming May , 2024 49 / 62


Minicomputers
Also known as mid-range computers, these became popular in the late
1960s but have become almost extinct because of the popularity of
personal computers. The latter can now perform most of the tasks
reserved for minis.
They became popular for control related functions as opposed to com-
puting purpose. Over the years, their usage was limited to dedicated
control assignments in mid-range organizations.

Eyob S. (AAiT) Computer Programming May , 2024 50 / 62


Servers

These are systems which are designed to provide resources, services


and functionality to client computers in a server-client network model.
Resources provided are based on the functions of a particular server,
which may fall under these categories: File server, Database server,
Print server, FTP servers, Application server, and Web server.
Servers are optimized to run 24 hours and are capable of hot swapping
of storage and other hardware without having to shut down the system.

Eyob S. (AAiT) Computer Programming May , 2024 51 / 62


Microcomputers/Personal Computers

Microcomputers are the smallest, least expensive and the most used
computer systems. They have a small memory, less processing power,
are physically smaller, and permit fewer peripherals compared to super
and mainframe computers.
They are more commonly known as personal computers or simply PCs.
Categories of personal computers include: Desktop computers, Mobile
computers, Wearable computers.

Eyob S. (AAiT) Computer Programming May , 2024 52 / 62


Single Board Computers

These are the smallest possible computers which mimic the shape and
functionality of full-size desktop motherboards.
An SBC can easily be confused with an embedded system because of
its size but is not, because it permits general purpose functionalities
synonymous with microcomputers.

Eyob S. (AAiT) Computer Programming May , 2024 53 / 62


Mobile Computers and Wearable Gadgets

The most common types of mobile computers include: Laptop com-


puters, Tablets, Smartphones, Personal Digital Assistants (PDA).
Wearable Gadgets, wearable computers, or simply wearables, are minia-
ture devices that are designed to be worn or attached onto your body.
Examples of these devices include smart watches, smart glasses, smart
clothes, smart shoes.

Eyob S. (AAiT) Computer Programming May , 2024 54 / 62


Embedded Systems

These are microprocessor-based systems which are standalone elec-


tronic hardware designed to perform dedicated computing tasks. They
are not general purpose installations like the personal computer.

The old cell phones used well before the smartphones became a phe-
nomenon, could easily fall under the category of embedded systems
since their sole purpose was to make and receive calls.

Smartphones today, however, have evolved into general purpose mo-


bile computers. Firmware on these systems is written in the read-only
memory (ROM) or flash memory chips.

Eyob S. (AAiT) Computer Programming May , 2024 55 / 62


Programming Constructs

Programming Constructs

Eyob S. (AAiT) Computer Programming May , 2024 56 / 62


Syntax

A line of code is syntactically valid and correct if it follows all the


rules of syntax. It is associated with the grammar and structure of the
programming language.

It doesn’t have any relationship with the meaning of the statement.

It does not have to do anything with the meaning of the statement.

Syntax errors are encountered after the program has been executed.

Some examples include: missing braces, using unassigned variable.


Such errors are easy to catch.

Eyob S. (AAiT) Computer Programming May , 2024 57 / 62


Semantics

It refers to the meaning of the associated line of code in a programming


language.

It tells about the meaning, and helps interpret what function the line
of code/program is performing.

The semantic errors are handled during runtime of the program execu-
tion.

Even when a statement has correct syntax, it wouldn’t do the function


that was intended for it to do. Such errors are difficult to catch.

Eyob S. (AAiT) Computer Programming May , 2024 58 / 62


Programming Language

Low level

High Level

Interpreted

Compiled

Eyob S. (AAiT) Computer Programming May , 2024 59 / 62


ASCII

Eyob S. (AAiT) Computer Programming May , 2024 60 / 62


Why Python?

Guido Van Rossum: Dutch programmer best known as the creator of

the Python programming language.

Philosophy: Code readability, few lines of code

General Purpose, Interpreted, High level

Eyob S. (AAiT) Computer Programming May , 2024 61 / 62


End of Chapter

Thank You!!!

Eyob S. (AAiT) Computer Programming May , 2024 62 / 62

You might also like