Unit 1 Python

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

NOTES

----------------------------------------------------------------------------------------------------------------
UNIT-1: INTRODUCTION TO PYTHON
INTRODUCTION TO PROGRAMMING
Programming is about writing the instructions which a computer follows to enable it to store
knowledge, process knowledge, and communicate knowledge with the outside world. Stemming
from storing knowledge we can move into data structures and databases.
It is the process of writing code to solve a particular problem or to implement a particular task.
Every time you turn on your smartphone, laptop, tablet, smart TV, or any other electronic
device, you are running code that was planned, developed, and written by developers. This code
creates the final and interactive result that you can see on your screen.
INTRODUCTION TO HARDWARE AND SOFTWARE
The term computer is derived from word ‘compute’ which means to calculate.

Computer System

A computer system consists of two major components, namely, hardware and software.

All physical components that forms computer system are known as computer hardware.

Software is basically collection of different programs that tells computer’s hardware what to
do.

Figure: Computer System

Hardware

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 1 of 28
All physical components that make up a computer is known as computer hardware.

It includes all components that we can see and touch i.e. processor, input devices like keyboard,
mouse, output devices like visual display unit (VDU), printer, speaker, connecting wires, casing,
storage devices etc. Block diagram depicting major components of computer is shown below:

Figure: Computer Block Diagram

Computer hardware consists of different functional units: input unit, central processing unit
(CPU) which consists arithmetic logic unit (ALU) and control unit (CU), memory unit and
output unit.

Computer accepts digital data from user with the help of input devices like mouse, keyboard,
microphone etc. Received data from user is either stored in the memory for later use or
immediately processed by the arithmetic and logic unit to carry out the desired operations. After
processing, processed output known as information is either stored in memory for later use or
sent to user with the help of output devices like monitor, printer, speaker etc. All the above
mentioned activities are controlled and coordinated by the control unit.

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 2 of 28
Software

Set of instructions that tells the computer hardware what to do is known as computer program.
This program or collection of such programs is known as computer software. Concept of
software is illustrated in following figure:

Lecture dated 12-09-2024(…

Figure: Illustration of Software

Software guides and tells computer hardware how to accomplish a task. Computer software can
be categorized into two broad categories as system software and application software

Introduction to Software

Computer software can be categorized into two broad categories as system software and
application software as shown in figure below:

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 3 of 28
Figure:

Categories of Software

System software are set of programs which are used to control computer activity and computer
hardware. System software also provides platform for application software. Application
software are those programs which are designed to perform specific task and application
software requires system software for their existence. Relationship among hardware, different
software and user is shown in following figure.

:
Hardware Figure Software and User Relation

System Software

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 4 of 28
These are set of computer programs which are required for controlling and managing the
hardware resources of a computer system. System software is required for the proper
functioning of the computer. System software usually interacts with hardware and provides
platform for running application software. In general system software controls overall computer
hardware and computer activity at the same time providing service to user.

Different examples of system software are:

1. Operating System:

An operating system is collection of computer programs that guides the computer


hardware to do different activities under variety of conditions. System software provides
common core services required for other software to run. It also performs resource
management and provides interface between the user and machine. The basic functions
of operating systems are:

1. Process Management
2. Memory Management
3. File Management
4. Device Management
5. Security Management
6. Creating User Interface
2. Device Drivers:

Device drivers are set of computer program that controls the operation and functionality
of different devices. Computer system is generally associated with different devices such
as keyboard, mouse, monitor, printer. Functioning of these device is controlled by device
drivers. Each device in the computer system has a device driver associated with it for
proper functioning.

Figure: Illustration of Device Drivers

3. Language Translators:

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 5 of 28
Since computer understands language consisting 0s and 1s. Language translators are
computer programs which translates program written in programming language to
machine language consisting sequence of 0s and 1s.

Figure: Programming Language Translators

4. Utility Software:

Like hardware, software in computer also needs maintenance. Utility software are
programs that are used to maintain, support, enhance and secure existing program.
Example of utility software includes back up software, antivirus, data recovery software,
disk management etc.

Application Software

These are set of computer programs which are designed to perform specific task. Application
software needs system software for its existence. User comes in contact with application
software to accomplish certain task and system software performs most of the tasks required for
application software in background.

Most commonly used application software are:

1. Word Processors:

These are used for creating documents such as letters, reports, articles etc. in required
format. Example includes Microsoft Word, Word Perfect etc.

2. Spreadsheets:

These are used for storing records, simple graphical tools, accounting tools, simple
calculations and numerical operations on data. Spreadsheets consists rectangular grids
which contains different cells. Example includes Microsoft Excel, Google Spreadsheets
etc.

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 6 of 28
3. Image Editors:

These applications are used for manipulation like rotation, cropping, zooming, changing
appearance, adjusting contrast etc. on images. Example includes Adobe Photoshop,
Adobe Illustrator, Picasa, Microsoft Paint etc.

4. Database Management System (DBMS):

These are used for storing, extraction and manipulation of data. Example includes
Microsoft Access, Oracle, MySQL etc.

5. Web Browsers:

These are used for accessing world wide web (www). Example includes Google
Chrome, Firefox, Microsoft Edge, Torch etc.
List out major differences between system software and application software
Major differences between system software and application software are pointed below:

System S/W: Set of computer programs that are designed to control computer hardware and to
provide service.
Application S/W: Computer program that is designed to perform specific task.

System S/W: System software manages computer resources and provides platform for the
execution of application software.
Application S/W: Application software manages their specific tasks to suit their needs.

System S/W: System software can exist as a lone entity.


Application S/W: Application software needs system software for its existence.

System S/W: Examples: MS Windows, Mac OS, Unix, Linux etc.


Application S/W: Examples: Web browsers, Word processor, Image Editors, Spreadsheets etc.
Machine language

Computer understands only machine language that uses 0s and 1s. It is the lowest level language
that computer understands. In machine language different instructions are formed by taking
combinations of 0s and 1s. The computer converts all high level languages into machine
language before executing any statements. Machine language is written in binary form that a
computer can execute directly. These are also known as machine code or object code. This
language is not feasible for humans to use because it consists entirely of binary numbers. If the
word length of the machine is 16 bits (two byte) and we have to add two numbers (say 2 and 4)
then we have to remember binary number that is used for addition (say 0100000011001100).
This language is fastest in terms of execution in the sense that it does not need to be translated.

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 7 of 28
Advantage of Machine Language

Machine language has following advantages :

1. Translation Free : Machine language is the only language that computer understands.
Program written in languages other than machine language must be translated to
machine language. However, the program written in machine language can be directly
executed without any translation.
2. High Speed : Since program written in machine language need not to be translated
and hence conversion time is saved which enables execution of machine language
program extremely fast.

Disadvantage of Machine Language

Machine language has following disadvantages :

1. Machine Dependent : Program written in machine language are machine dependent


and hence program developed for one system does not execute on other system.
2. Complex Language for Programming : Since machine language consists only
sequence of 0s and 1s, so it is very difficult for programmer to remember and write each
instructions.
3. Error Prone : While programming using machine language everything need to be
expressed in sequence of 0s and 1s which is very tedious task. So errors are frequently
occurred while programming using machine language.
4. Time Consuming : Writing program in machine language is time consuming process.

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 8 of 28
Low vs High Level Language
(Differences)
Major differences between low level language and high level language
are pointed out as :

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 9 of 28
What is Translators? Different type of translators.
A program written in high-level language is called as source code. To convert the source code
into machine code, translators are needed.

A translator takes a program written in source language as input and converts it into a program
in target language as output.

It also detects and reports the error during translation.

A program written in high-level language is called as source code. To convert the source code
into machine code, translators are needed.

A translator takes a program written in source language as input and converts it into a program
in target language as output.

It also detects and reports the error during translation.


Compiler

Compiler is a translator which is used to convert programs in high-level language to


low-level language. It translates the entire program and also reports the errors in
source program encountered during the translation.

Interpreter

Interpreter is a translator which is used to convert programs in high-level language


to low-level language. Interpreter translates line by line and reports the error once
it encountered during the translation process.

It directly executes the operations specified in the source program when the input is
given by the user.

It gives better error diagnostics than a compiler.

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 10 of 28
Differences between compiler and interpreter

SI. No Compiler Interpreter

1 Performs the translation of a Performs statement by statement


program as a whole. translation.

2 Execution is faster. Execution is slower.

3 Requires more memory as linking is Memory usage is efficient as no


needed for the generated intermediate object code is
intermediate object code. generated.

4 Debugging is hard as the error It stops translation when the first


messages are generated after error is met. Hence, debugging is
scanning the entire program only. easy.

5 Programming languages like C, C++ Programming languages


uses compilers. like Python, BASIC, and Ruby uses
interpreters.

PROBLEM FORMULATION AND SOLVING


Problem formulation means defining the problem and its requirements. It is an art
of analysing the aim and objectives of real life situations and properly describing
the problem.
It includes requirements and objectives that are essential for problem solving.
Problem Solving involves identifying an innovative method for solving the problem
that is formulated.
It includes what we need to do to achieve a favourable outcome.
1. What are the main substeps/operations in this problem?
2. What data is going in/out of the operations?
3. What is the logical flow of how they fit together?

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 11 of 28
• Step-1: Identifying the problem
To check whether a number is even or odd.

• Step-2: Collection of all available information


What is an Even Number?

An even number is an integer number which is exactly divisible by 2.


Example: 0, 6, 8, 46, 168

What is an Odd Number?

An odd number is an integer which is not exactly divisible by 2.


Example: 1, 9, 13, 19, 51, 101

• Step-3: Possible sets of solution

• Step-4: Best solution

UNIT-1
INTRODUCTION TO PYTHON

https://docs.google.com/document/u/1/d/1NWARNvL6WUCk3vc4z9SE3NLrhzsN3EPE/mobilebasic 24/09/24, 23:46


Page 12 of 28

You might also like