A.
M JAIN COLLEGE, MEENAMBAKKAM
DEPARTMENT OF SOFTWARE APPLICATIONS
CLASS: I BSC SA SUBJECT: PYTHON PROGRAMMING
UNIT -1
What is Computer Science?
Computer science is fundamentally about computational problem solving.
That is, solving problems by the use of Computation. One characterization of
computation is given by the notion of an algorithm .
An algorithm is a series of steps that can be systematically followed for producing
the answer to a certain type of problem.
The Essence of Computational Problem Solving
In order to solve a problem computationally, two things are
needed:
✔ Representation that captures all the relevant aspects of the problem.
✔ Algorithm that solves the problem by use of the representation.
There is a simple algorithmic approach for solving this problem by simply trying
all possible combinations.
Trying all possible solutions to a given problem is referred to as Brute force
approach.
A representation that leaves out details of what is being
represented is a form of abstraction .
The use of abstraction is prevalent in computer science.
Limits of Computational Problem Solving
Once an algorithm for solving a given problem is developed or found, the next
important thing is a solution to the problem be found in a reasonable amount of
time?” If not, then the particular algorithm is of limited practical use.
------------------------------------------x-------------------------------------------
Computer Algorithms
An algorithm is a precise step-by-step sequence of instructions or a set of
rules to be followed in order to solve a specific problem or perform a computation.
In computational problem-solving, algorithms are fundamental tools used
to design efficient and effective solutions.
An algorithm is a finite number of clearly described, unambiguous “doable”
steps that can be systematically followed to produce a desired result for given
input in a finite amount of time.
Algorithms solve general problems and not specific ones .
Algorithms, therefore, are general computational methods used for solving
particular problem instances.
Computer algorithms are central to computer science.
They provide step-by-step methods of computation that a machine can carry
out. Having high-speed machines (computers) that can consistently follow and
execute a given set of instructions provides a reliable and effective means of
realizing computation.
However, the computation that a given computer performs is only as good as
the underlying algorithm used
Understanding what can be effectively programmed and executed by
computers, therefore, relies on the understanding of computer algorithms.
Pseudocode is an informal high-level description of an algorithm while
flowchart is a pictorial representation of an algorithm.
Example:
--Write farmer,duck,wolf steps here
------------------------------------------X-------------------------------------------------
Computer Hardware
Computer hardware comprises the physical part of a computer system.
It includes the all-important components of the central processing unit (CPU)
and main memory. It also includes peripheral components such as a keyboard,
monitor, mouse, and printer.
It is essential that computer hardware be reliable and error free. If the hardware
gives incorrect results, then any program run on that hardware is unreliable.
The key to developing reliable systems is to keep the design as simple as
possible. In digital computing, all information is represented as a series of
digits.
We are used to representing numbers using base 10 with digits 0–9. In current
electronic computing, each digit is represented by a different voltage level.
It is a fact of information theory, however, that any information can be
represented using only two symbols. All information within a computer system
is represented by the use of only two digits, 0 and 1 , called binary
representation .
In this representation, each digit can be one of only two possible values, similar
to a light switch that can be either on or off.
Computer hardware, therefore, is based on the use of simple electronic “on/off”
switches called transistors that switch at very high speed.
Integrated circuits (“chips”), the building blocks of computer hardware, are
comprised of millions or even billions of transistors.
Fundamental Hardware Components
The central processing unit (CPU) is the “brain” of a computer system,
containing digital logic circuitry able to interpret and execute instructions.
Main memory is where currently executing programs reside, which the CPU
can directly and very quickly access. Main memory is volatile; that is, the
contents are lost when the power is turned off.
Secondary memory is nonvolatile, and therefore provides long-term storage of
programs and data.Input/output devices include anything that allows for input
or output.
Finally, buses transfer data between components within a computer system,
such as between the CPU and main memory. Operating System
-Bridging Software and Hardware
An operating system is software that has the job of managing and interacting
with the hardware resources of a computer.Because an operating system is
intrinsic to the operation a computer, it is referred to as system software .
An operating system acts as the “middle man” between the hardware and
executing application programs .
For example, it controls the allocation of memory for the various programs that
may be executing on a computer. Operating systems also provide a particular
user interface.
Thus, it is the operating system installed on a given computer that determines
the “look and feel” of the user interface and how the user interacts with the
system, and not the particular model computer.
The Binary Number System
For representing numbers, any base (radix) can be used.
For example, in base 10, there are ten possible digits (0, 1, . . ., 9), in which
each column value is a power of ten. Other radix systems work in a similar
manner. Base 2 has digits 0 and 1, with place values that are powers of two.
In digital computing, all information is represented as a series of digits.
All information within a computer system is represented by the use of only two
digits, 0 and 1 , called binary representation . The term bit stands for binary
digit Every bit has the value 0 or 1.
A byte is a group of bits operated on as a single unit in a computer system,
usually consisting of eight bits.Binary representation is used in digital
computing because of the resulting simplicity of hardware design.
-----------------------------------------------------X---------------------------------------
Computer Software
Computer software is a set of program instructions, including related data and
documentation, that can be executed by computer.
It enable computer to carry out specific functions.
It actually tells the computer what to do and how to do it.This can be in the
form of instructions on paper, or in digital form.
Computer software is divided in to two broad categories:
System software
Application software
o System software is intrinsic to a computer system, application
software fulfills users’ needs. System software is a collection of
programs designed to operate, control, and extend the processing
capabilities of the computer itself.
o System software manages the computer resources . It provides the
interface between the hardware and the users. Some examples of
system software are Operating System, Compilers, Interpreter,
Assemblers, etc.
o Application software products are designed to satisfy a particular need
of a particular environment. Application software, on the other hand is
directly responsible for helping users solve their problems.
o software may consist of a single program, such as Microsoft's notepad
for writing and editing a simple text or a collection of programs, often
called a software package, which work together to accomplish a task,
such as a spreadsheet package.
COMPUTER LANGUAGES
To write a program (tells what to do) for a computer, we must use a computer
language. Over the years computer languages have evolved from machine
languages to natural languages.
Language Machine:
In the earliest days of computers, the only programming languages available
were machine languages. Each computer has its own machine language which
is made of streams of 0‘s and 1‘s.
The instructions in machine language must be in streams of 0‘s and 1‘s. This is
also referred as binary digits. These are so named as the machine can directly
understood the programs
Assembly Language:
These early programming languages simply mirrored the machine languages
using symbols or mnemonics to represent the various language instructions.
These languages were known as symbolic languages. Because a computer does
not understand symbolic language it must be translated into the machine
language.
A special program called an Assembler translates symbolic code into the
machine language. Hence they are called as Assembly language.
High-Level Languages:
A high-level language is a programming language that enables a programmer to
write programs that are more or less independent of a particular type
of computer.
Such languages are considered high-level because they are closer to human
languages and further from machine languages.
Syntax, Semantics, and Program Translation
Programming languages are languages just as “natural languages” Syntax and
semantics are important concepts that apply to all languages.
The syntax of a language is a set of characters and the acceptable arrangements
of those characters. The semantics of a language is the meaning associated with
each syntactically correct sequence of characters.
Thus, every language has its own syntax and semantics.
Syntax – the form of the expressions, statements, and program units
Semantics - the meaning of the expressions, statements, and program units.
Program Translation
A central processing unit (CPU) is designed to interpret and execute a specific
set of instructions represented in binary form (i.e., 1s and 0s) called machine
code. Only programs in machine code can be executed by a CPU.
Writing programs at this “low level” is tedious and error-prone. Therefore, most
programs are written in a “high-level” programming language such as Python.
Since the instructions of such programs are not in machine code that a CPU can
execute, a translator program must be used.
There are two fundamental types of translators. One, called a compiler,
translates programs directly into machine code to be executed by the CPU. The
other type of translator is called an interpreter , which executes program
instructions in place.
Thus, an interpreter can immediately execute instructions as they are entered.
This is referred to as interactive mode. This is a very useful feature for program
development. Python is executed by an interpreter. On the other hand, compiled
programs generally execute faster than interpreted programs.
Language Translators
These are the programs which are used for converting the programs in one
language into machine language instructions, so that they can be excuted by the
computer.
1) Compiler: It is a program which is used to convert the high level language
programs into machine language
2) Assembler: It is a program which is used to convert the assembly level
language programs into machine language
3) Interpreter: It is a program, it takes one statement of a high level language
program, translates it into machine language instruction and then immediately
executes the resulting machine language instruction and so on.
Program Debugging: Syntax Errors vs. Semantic Errors
Program debugging is the process of finding and correcting errors (“bugs”) in a
computer program. Programming errors are inevitable during program
development. Syntax errors are caused by invalid syntax
-----------------------------------------X-------------------------------------------------
------------------------------------------------------------X-------------------------------------------------
------------------------------------------------------------------X--------------------------------------------------------------
------------------------------------------------------------X--------------------------------------------------------------