You are on page 1of 248

for more updates visit: www.python4csip.

com
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR

TYPES OF SOFTWARE
for more updates visit: www.python4csip.com

Introduction

Computer being an electronic device, understands only electric


pulses i.e. whether the electricity is flowing through a circuit or
not. We denote these two states of pulses (electricity flowing &
not flowing) by 1 and 0, and thus computer understands a
language that consists of only two 'characters' namely 1 and 0.
This special language is popularly known as Binary language or
Machine language, which is directly understood by the
computer. 0 and 1, the digits of binary language or Binary
Digits are also known as Bits (Binary Digits). Binary language
consists of ones and zeros, typically in groups of 8 or 16 bits,
used for storing characters and numbers.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Interacting with Hardware

An ordered set of instructions given to the computer is known as a


program and a set of such PROGRAMS that governs the operation of
a computer system and/or its related devices is known as SOFTWARE.

User
Appn Software
System software

Hardware

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Types of Software

Type Of Software

System Software Application Software

BIOS Word Processor

Operating System Spread sheet

Device Driver Presentation

Language Processor Database


VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

System Software
 The functions of all the physical components of a computer
system are guided by some instructions or program collectively
known as System Software. System Software controls all
internal activities inside a computer system and between all
attached components of a computer system.

 Major activities performed by System Software are :-


 Reads data and instructions through the input devices
 Translates all data and instruction into computer
understandable form and vice versa
 Controls all devices attached to the computer system
 Processes and generates the result on the output devices

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

System Software - OS
 Operating system is a set of system programs that controls and
coordinates the operations of a computer system. It provide
interaction between user and computer.
 It is stored (installed) on the hard disk or any other external storage
device.
 It is the first program to be executed on a computer after the BIOS.
 Need of Operating system: it provides a software platform, on top
of which, other programs, called application programs are run.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

System Software - OS
 Major Functions of Operating System are :-
 Device Manager - Communicate with hardware and the attached
devices.
 Memory Manager - Manage different types of memories

 Interface Manager - Provide a user interface

 Program Manager - Provide a structure for accessing an application

 Task Manager - Enable users to manipulate programs and data

 File Manager - Manage the files, folders and directory systems on a


computer
 Network Manager - Provide basic networking structure for LAN and
Internet
 Security Manager - A smart OS also provides a minimal security to the
computer system through authorization (user name) and authentications
(password)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

User Interface
 It is the medium by which user interact with any
software. This interface may by text based on
graphical based or it may be touch screen.
 Based on this User interface may be categorized
as:
 CUI(Character User Interface)
 GUI (Graphical User Interface)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Character User Interface


 This type of interface requires user to type each
instructions on its prompt to send request to
computer.
 User must remember each command with proper
syntax to perform its operation.
 It is not very easy and user friendly.
 Example of this type of interface was DOS (Disk
Operating System), it is still available with windows
as CMD program where we can type the DOS
commands
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Character User Interface


for more updates visit: www.python4csip.com

Graphical User Interface


 It is more user friendly interface than CUI which uses
images, icons to represent the option, commands.
 Various GUI components are used like: Labels, Text
Box, Buttons, Check Box, Radio Buttons, List Box,
Combo Box, Password field, Menus, Dialog Box etc.
 GUI Interface is Event Drive i.e. user must perform
event like – Click, Double Click, Drag to trigger the
action.
 Now days every OS/Applications are GUI based
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Graphical User Interface


LABEL

TEXT BOX

DROP
DOWN LIST

RADIO BUTTON

BUTTON

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Touch Screen Interface


 A touch screen is a computer/mobile display screen
that is allows user to interact with the application by
directly touching it by hand or by stylus. The screens
are sensitive to pressure; a user interacts with the
computer by touching pictures or words on the screen.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

System Software - BIOS


 The basic input/output system (BIOS) is also commonly
known as the System BIOS. The BIOS is boot firmware, a
small program that controls various electronic devices
attached to the main computer system.
 It is designed to be the first set of instructions run by a
Computer when powered on. The initial function of the
BIOS is to initialize system devices such as the RAM, hard
disk, CD/DVD drive, video display card, and other
hardware.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Device Driver
 A device driver is a system software that acts like an
interface between the Device and the user or the
Operating System. All computer accessories like Printer,
Scanner, Web Camera, etc. come with their own driver
software. These driver software help the operating system
and other application software to communicate with those
devices for optimal use

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Language Processor
 As discussed computer understand only binary language
so it is very difficult for the programmer to write the entire
program as a bunch of 0 and 1. So need arises to have a
language which is easy to write, learn and understand.
The solution was High Level Languages which used simple
English like statements to write the application.
 Common Language processors are :
 Compiler
 Interpreter

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Application Software
 Application software runs on Operating system. It uses the
services of operating system to interact with hardware.
 Set of software to carry out specific task like creating
documents (word processor ), calculations and analysis
(Spreadsheet), Presentations (Power point), Railway
reservation, library management etc.
 It is of 4 type:
 Utility software

 General Purpose Software

 Customized software

 Developer tool

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Utility Software
 Utility software for efficient working of our computer and other task.
 Various utility softwares available like
 Text Editor : for storing short notes, message, coding. Examples
are : Notepad, Notepad++, WordPad
 To-Do task : to manage the work.
 Compression : to compress i.e. reduce the size of file to transfer
file from one computer to another. Examples are : WinZip,
WinRAR, jZIP etc.
 Disk Defragmenter : Disk de-fragmentation utility software
speeds up the system by rearranging such fragmented files
stored on a disk in contiguous locations in order to optimize the
system performance.
 Anti-Virus : to protect our computer from threats like Virus, worm,
Trojan horse, banking frauds etc.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

General Purpose software


 These are the common software used by everyone in the
world. Examples are:
 Word Processing : for creating document, letters,
applications. Example : MS-Word, Writer etc
 Spreadsheet : for storing data in tabular form, performing
simple calculation, visualization etc. Examples : MS-Excel,
calc.
 Presentation : for creating personal of professional
presentation in attractive and interactive way. Examples:
MS-PowerPoint, Impress
 Database : to store huge amount of data and also perform
queries on stored data. Examples: Oracle, MySQL, etc
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Customized Software
 These are tailored software i.e. it is created as per
the need of the customer for their specific
requirement like – for maintaining school operation,
Restaurant management, banking, Hotel, Hospital
management etc.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Developer tools
 When a programmer starts the process of writing a
program to develop software for any type of application,
he/she requires a series of software developing tools like
code editor, debugger and compiler. A platform where all
these software developing tools are bundled into a
package is known as Integrated Development Environment
(IDE).
 Popular development tools are : Net Beans, Eclipse, IDLE,
Visual Studio.
 Each IDE provides features of: Editor, Compiler/Interpreter,
Debugger, Automation tool, output window etc.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Compiler
 Compilers are used to convert High Level Language
program to machine language
 It convert the entire program in machine language
in one go.
 If encounter errors, it report all the error along with
the line number.
 It convert HLL code in machine code if all errors are
remove, once converted we can directly execute
program without interacting with the compiler.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Interpreter
 It is also used for converting HLL into machine
language.
 It translate the HLL code line by line as well as
execute at the same time.
 If any error occurs, it stops the execution and report
the error.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Difference between Compiler and Interpreter

COMPILER INTERPRETER
It convert the HLL code to machine It convert the HLL code to machine
code in one go code line by line
It report all the error after compilation It report error for only that line where
error encountered
It execute program only when all It convert and execute simultaneously
errors are rectified
It is fast It is slow as compare to compiler
It takes less memory, because after It takes more memory because
conversion compiler is not required in Interpreter is required in memory with
memory with execution every execution.
Not suitable for debugging purpose Suitable for debugging purpose
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Digital Systems:
Boolean Algebra and
Logic Gates

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

DEFINITION:

Boolean Algebra is the algebra of


truth values and operations
performing on them which is used
in Digital Circuits for performing
logical operations.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Boolean Constants and Variables

 Logical statements can have either two values yes or


no, true or false, 0 or 1.
 Boolean 0 and 1 do not represent actual numbers
but instead represent the state, or logic level.

Logic 0 Logic 1
False True
Off On
Low High
No Yes
Open switch Closed switch
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Truth Tables

 A truth table is a means for describing how a logic


circuit’s output depends on the logic levels present at
the circuit’s inputs.

Inputs Output
A B x
A
1 1 1
? x
0 1 0
B
1 0 0
0 0 0
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Three Basic Logic Operators

 OR
 AND
 NOT

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

OR Operation

 Boolean expression for the OR operation:


x =A + B
 The above expression is read as “x equals A OR B”

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

AND Operation

 Boolean expression for the AND operation:


x =A B
 The above expression is read as “x equals A AND
B”

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

NOT Operation

 The NOT operation is an unary operation, taking only one


input variable.
 Boolean expression for the NOT operation:
x= A
 The above expression is read as “x equals the inverse of
A”
 Also known as inversion or complementation.
 Can also be expressed as: A’

A
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

LOGIC GATES
 OR
 AND
 NOT
 NAND
 NOR

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

OR Gate

 An OR gate is a gate that has two or more inputs


and whose output is equal to the OR combination of
the inputs.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

AND Gate

 An AND gate is a gate that has two or more inputs


and whose output is equal to the AND product of the
inputs.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

NOT Gate

The symbol and Truth Table for NOT gate is given below:

A
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Describing Logic Circuits


Algebraically
 Any logic circuits can be built from the three basic
building blocks: OR, AND, NOT
 Example 1: x = A B + C
 Example 2: x = (A+B)C
 Example 3: x = (A+B)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Examples 1,2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Examples 3

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Evaluating Logic-Circuit
Outputs

 x = ABC(A+D)

 Determine the output x given A=0, B=1, C=1, D=1.


 Can also determine output level from a diagram

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Examples

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Draw the Logic Gate:


 AB+C’D
 A(B+C’) + B’D’
 A’ [ (B+C)’ + AB]

Draw the Truth Table:


 AB+(BC)’
 A(B’+C’) + BC’
 X’[ (Y+Z)’ + XY]

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Derive the Boolean Expression

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

NAND Gate

 Boolean expression for the NAND operation:


x=AB

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

NOR Gate

 Boolean expression for the NOR operation:


x=A+B

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Boolean Theorems and Laws

 x* 0 =0 Fallacy
 x+1=1 Tautology
 x*x=x Indempotence Law
 x+x=x Indempotence Law
 x*x’=0 Complementarity Law
 x+x’=1 Complementarity Law
 x” = x Involution Law
 x+0=x
 x* 1 =x
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Boolean Theorems and Laws

 x+y = y+x // Commutative Law


 x*y = y*x
 x+(y+z) = (x+y)+z=x+y+z // Associative Law
 x(yz)=(xy)z=xyz
 x(y+z)=xy+xz // Distributive Law
 (w+x)(y+z)=wy+xy+wz+xz
 x+xy=x // Absorption Law

Prove it by Truth Table

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

De’Morgan’s Theorems
(Break the line change the sign)

 (x+y)’=x’y’
 Implications and alternative symbol for NOR function
 (xy)’=x’+y’
 Implications and alternative symbol for NAND function
 Process of Demorganization:
(i) Complement entire function
(ii) Change all AND to OR and all OR to AND
(iii) Complement each of the individual variables

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Demorgan’s Theorum

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Demorgan’s Theorum

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Universality of NAND Gates

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Universality of NOR Gates

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decimal Number System


Binary Number System
Octal Number System
Hexadecimal Number System
ASCII, ISCII, UNICODE

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Computers accept input and deliver output in the form of digital


signals.
A digital signal has only two states, represented by two voltage
levels, high and low.
For a computer to process numbers, it is important to be able to
represent the numbers as digital signals.
To achieve this, you need a number system that uses only two symbols
to represent any number.
The binary number system uses only two symbols, 0 and 1, to
represent any number, and therefore provides a direct way of
representing numbers in computers.
Two other number systems, octal and hexadecimal, help represent
binary numbers concisely, making it convenient to deal with large
strings of 0s and 1s.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

A number system is known by its radix or base.


The decimal number system uses 10 symbols, and therefore, has
a radix or base of 10. The binary number system uses two
symbols, and therefore, has a radix of 2.
The radix of a number is usually written as a subscript with that
number, where the number is written within parentheses, as
shown in the following examples:
 (368)10
 (10101)2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• The decimal number system uses 10 symbols, and therefore has


a radix or base of 10.
• Symbols are [ 0 to 9 ]
• Every digit in Decimal number system is identified from its
position i.e. from right to left as (for e.g. 345) :-
Number 3 4 5
POSITIONAL VALUE 102 101 100
• It means : 3 x 102 + 4 x 101 + 5 x 100 = 345
• 3 x 100 + 4 x 10 + 5 x 1 = 345
• Left most digit will be MSD (most significant digit and right most
digit will be LSD (least significant digit)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• The binary number system uses 2 symbols, and therefore has a radix
or base of 2.
• Symbols are [ 0 and 1 ], also known as bits or binary digit
• Every bit in Binary number system is identified from its position i.e.
from right to left as (for e.g. 110) :-

Binary Number 1 1 0
POSITIONAL VALUE 22 21 20
• It means : 1 x 22 + 1 x 21 + 0 x 20 will give its decimal equivalent
• 1 x 4 + 1 x 2 + 0 x 1 = 6, So (110)2 = (6)10
• Left most digit will be MSB (most significant bit and right most digit
will be LSB (least significant bit)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• The octal number system uses 8 symbols, and therefore has a


radix or base of 8.
• Symbols are [ 0 to 7 ]
• Every bit in Octal number system is identified from its position
i.e. from right to left as (for e.g. 140) :-

Binary Number 1 4 0
POSITIONAL VALUE 82 81 80
• It means : 1 x 82 + 4 x 81 + 0 x 80 will give its decimal
equivalent
• 1 x 64 + 4 x 8 + 0 x 1 = 96, So (140)8 = (96)10
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• The Hex number system uses 16 symbols, and therefore has a


radix or base of 16.
• Symbols are [ 0 to 9 and A to F ]
• 10 is represented as A and so on
• Every bit in Hex number system is identified from its position i.e.
from right to left as (for e.g. A2B) :-

Binary Number A 2 B
POSITIONAL VALUE 162 161 160
• It means : Ax162 + 2x161 + Bx160 will give its decimal equivalent
• 10x256 + 2x16 + 11x1 = 2603, So (A2B)16 = (2603)10
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

At times, you need to covert a number from one number system
to another.
Distinct methods have been defined for conversion between
each pair of number systems.
You can convert a decimal number to its binary form by using
the method of successive division by 2, the radix of the binary
number system.
Put the remainder to the right of quotient and repeat this
process till the quotient becomes ZERO or ONE.
Write down the remainders in reverse order to get equivalent
binary number.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

LSB

MSB

ANSWER: (101101)2
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• (79)10 to ( ? )2
• (30)10 to ( ? )2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiply each bit of binary number by its place value i.e. 2n


Add the result.

1 0 1 0 1 1 0 1
27 26 25 24 23 22 21 20

128 x 1 64 x 0 32 x 1 16 x 0 8x1 4x1 2x0 1x1

128 0 32 0 8 4 0 1

ANSWER: (73)10
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 11110110) 2 t o ( ? ) 10
• ( 101010110101) 2 t o ( ?) 10

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

You can convert a decimal number to its octal form by using the
method of successive division by 8, the radix of the octal
number system.
Put the remainder to the right of quotient and repeat this
process till the quotient becomes ZERO.
Write down the remainders in reverse order to get equivalent
octal number.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

LSD

MSD

ANSWER: (135)8
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 173) 10 to ( ? ) 8
• ( 243) 10 to ( ? ) 8

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiply each bit of octal number by its place value i.e. 8n


Add the result

2 3 7
82 81 80

64x2 8x3 1x7

128 24 7

ANSWER: (159)10
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

You can convert a decimal number to its octal form by using the
method of successive division by 16, the radix of the
hexadecimal number system.
Put the remainder to the right of quotient and repeat this
process till the quotient becomes ZERO.
Write down the remainders in reverse order to get equivalent
hexadecimal number.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

LSD

A=10
B=11, and so on.
..
MSD

ANSWER: (B2)16
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 233) 10 to ( ? ) 16
• ( 79) 10 to ( ? ) 16

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiply each bit of hexadecimal number by its place value i.e.


16n
Add the result

A 2 B
162 161 160

256x10 16x2 1x11

2560 32 11

ANSWER: (2603)10
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• As number of bits increases, there is a need arises of grouping


of bits.
• Octal number comprises of 3 bits i.e. 3 binary bits are used to
represent octal number.
OCTAL BINARY
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

3 5 2
011 101 010

ANSWER: (011101010)2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 237) 8 to ( ? ) 2
• ( 206) 8 to ( ? ) 2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• It requires grouping of 3 bits from right hand side, if last group


not consists of 3 bit then add 0 to make it group of 3 bit

MAKE GROUP OF 3 BITS

3 2 6 6

Extra 0 is ANSWER: (3266)8


padded to make
it of 3 bits VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 111000111001) 2 t o ( ? ) 8
• ( 101010101010101) 2 t o ( ? ) 8

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Hexadecimal number comprises of 4 bits i.e. 4 binary bits are


used to represent Hexadecimal number.
HEXADECIMAL BINARY HEXADECIMAL BINARY
0 0000 A 1010
1 0001 B 1011
2 0010 C 1100
3 0011 D 1101
4 0100 E 1110
5 0101 F 1111

6 0110
7 0111
8 1000
9 1001

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

8 B C 2
1000 1011 1100 0010

ANSWER: (1000101111000010)2
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( CA FE) 16 to ( ? ) 2
• ( 78F9) 16 to ( ? ) 2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• It requires grouping of 4 bits from right hand side, if last group


not consists of 4 bit then add 0 to make it group of 4 bit

MAKE GROUP OF 4 BITS

6 B 6 6

Extra 0 is ANSWER: (6B66)8


padded to make
it of 4 bits VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• ( 10101010101010101) 2 t o ( ? ) 16
• ( 110011110001101) 2 t o ( ? ) 16

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• To perform binary addition, we have to follow the simple rules


like:
• 0+0=0
• 0+1=1
• 1 + 1 = 0 (and 1 carry to left)
• 1 + 1 + 1 = 1 ( and 1 carry to left )

• Note : if number of 1’s is in even then result will be 0 and n no. of


1 will carry to left where n is the number of pair
• If the number of 1’s in in odd the result will be 1 and n no. of 1
will carry to left where n is the number of pair

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

CARRY

ADDITION
RESULT

ANSWER : 1100011
CARRY

ADDITION
RESULT

ANSWER : 11110001
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Computer must understand the character entered by user, for


this purpose numeric code is assigned to each character used in
computer.
• For example
• A–Z assigned with code 65-90
• a-z assigned with code 97-122
• 0-9 assigned with code 48-57
• There are various encoding scheme available
• ASCII
• ISCII
• UNICODE

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Stands for American Standard code for information


interchange.
• It is most widely used alphanumeric code for microcomputers
and minicomputers.
• It is 7-Bit code, so it can represent maximum of 27 = 128 code
i.e. 128 possible characters.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

CHARACTERS DECIMAL CODE 7-BIT CODE


A 65 1000001
BASED ON
B 66 1000010
THESE VALUE WE
- - - CAN EASILY
Z 90 1011010 FIND ITS OCTAL
& HEXADECIMAL
a 97 1100001
REPRESENTATIO
- - - N
z 122 1111010
ENTER KEY 13 0001101
$ 36 0100100
+ 43 0101011
- - -
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• CONVERT THE FOLLOWING ASCII CODE INTTO ITS ORIGINAL


MESSAGE
• 1000101 1011000 1000001 1001101
• To convert the above message we first convert the above 7-bit
code into decimal value as –
• 1000101 = 69 (it is code of ‘E’)
• 1011000 = 88 (it is code of ‘X’)
• 1000001 = 65 (it is code of ‘A’)
• 1001101 = 77 (it is code of ‘M’)
• So the original message is EXAM

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• CONVERT THE FOLLOWING MESSAGE INTO ASCII CODE


• STEP 1
• To convert first find out the binary value (either from ASCII
table) or manually we find out the decimal code then convert it
in binary. For e.g. if ‘A’ is 65 then following the sequence we can
find S = 83, T = 84, E = 69, P = 80
• SPACE = 32, 1 = 49
• Now convert the decimal into binary:
• 83 = 1010011, 84 = 1010100, 69 = 1000101, 80 = 1010000
• 32 = 0100000, 49 = 0110001
• So, original message:
• 1010011 1010100 1000101 1010000 0100000 0110001
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Stands for Indian Standard Code for Information Interchange


• ISCII we adopted in 1991, by Bureau by Indian Standards to
have common standard for Indian scripts.
• It is 8-bit encoding scheme and can represent 28 =256 chars.
• It retain first 128 for ASCII code
• ASCII is able to represent Indian language characters like :
Tamil, Telugu, Kannada, Oriya, Bengali, Assamese, Gujarati, etc.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• As we know ASCII and ISCII represent characters belonging to


different language by assigned unique code to each characters.
• Need arises to have encoding scheme which can represent all
the known language around the world. The result is UNICODE.
• It is the standard used worldwide now.
• Its variants are UTF-8, UTF-16, UTF-32
• Unicode 13.0 represent 143000 characters
• Supported by most OS, making it platform, vendor, application
independent
• Allows data to be transported between different system without
distortion.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• It is variable length encoding scheme that can represent each


character in UNICODE character set.
• The code unit of UTF-8 is 8 bits i.e. OCTET
• UTF-8 can use 1 OCTET to maximum 6 OCTET depending upon the
character it represent.
• Unicode code points are written as U+<codepoint> for e.g. U+0050
represent ‘P”
Unicode Code Points Unicode Code Points Number of
(Decimal) (Hex) octets used
U-0 to U-127 U+00 to U+07F 1 octet (8 bits)
U-128 to U-2047 U+80 to U+7FF 2 octets (16 bits)
U-2048 to U-65535 U+800 to U+FFFF 3 octets (24 bits)
U-65536 to U-2097151 U+10000 to U+1FFFFF 4 octets (32 bits)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• 1 OCTET (8 BIT REPRESENTATION)


• For 1 octet representation the left most bit act as control bit
which stores ZERO (0)
• The control bit is special bit that store the control code not the
actual character. Rest of the bit stores the actual’s binary
code
• For Example ( U + 0050 ) (Binary value of P is 1010000)

0 1 0 1 0 0 0 0

ACTUAL BINARY CODE

CONTROL CODE
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• 2 OCTET (16 BIT REPRESENTATION)


• First 3 bits (left most) of first octet will be 110
• First 2 bits (left most) of second octet will be 10
• For Example ( U + 00A7) (Binary value of  is 10100111)
EMPTY BITS
1 1 0 0 0 0 1 0 OCTET 1

1 0 1 0 0 1 1 1 OCTET 2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• 3 OCTET (24 BIT REPRESENTATION)


• First 4 bits (left most) of first octet will be 1110
• First 2 bits (left most) of second octet will be 10
• First 2 bits (left most) of third octet will be 10
• For Example ( U + 203B)
• (Binary value of ※ is 10000000111011)
EMPTY BITS
1 1 1 0 0 0 1 0 OCTET 1

1 0 0 0 0 0 0 0 OCTET 2

1 0 1 1 1 0 1 1 OCTET 3

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• 4 OCTET (32 BIT REPRESENTATION)


• First 5 bits (left most) of first octet will be 11110
• First 2 bits (left most) of 2nd , 3rd , 4th octet will be 10
• For Example ( U + 12345)
• (Binary value of ฀ is 00010010001101000101)
EMPTY BIT

1 1 1 1 0 0 0 0
OCTET 1
1 0 0 1 0 1 0 0
OCTET 2
1 0 0 0 1 1 0 1
OCTET 3
1 0 0 0 0 1 0 1
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• It is fixed length encoding scheme that uses exactly 4 bytes to


represent all Unicode characters.
• It stores every character using 4 bytes
• Example: Consider the Symbol * [U+002A binary-00101010]

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 1 0 1 0 1 0

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Introduction to Problem Solving

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

What is Problem solving?


 Problem solving is a process of transforming the
description of a problem into the solution of
that problem by using our knowledge of the
problem domain and by relying on our ability to
select and use appropriate problem-solving
Strategies, Techniques and Tools.
 Problem solving (with in the context of
developing programs) refers to analyzing a
problem with the intention of deriving a
solution for the problem

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

SDLC – Software Development Life Cycle

REQUIREMENTS

ANALYSIS

DESIGN

CODING

TESTING

IMPLEMENTATION

DOCUMENTATION
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

REQUIREMENTS
What the problem is?
 What is needed to solve it?
What the solution should provide
If there are constraints and special
conditions?

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

ANALYSIS
 INPUTS: To the problem, their form
and the input media to be used.
 OUTPUTS: Expected from the
problem, their form and the output media
to be used.
 Special constraints or (necessity)
conditions (if any).
 Formulas or equations to be used

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

DESIGN
 In Design phase, we design the proposed
solution without writing a computer
program by using the techniques:
◦ Algorithm
◦ Pseudocode
◦ Flow Chart

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Coding
 It is the process of transforming design
(Algorithm, Pseudocode, Flow Chart) in a
computer program using any
programming language.
 The output of program must be the
solution of intended problem.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Testing
 program testing is the process of executing a
program to demonstrate its correctness.
 Program verification is the process of
ensuring that a program meets user
requirement
 After the program is compiled we must run
the program and test/verify it with different
inputs before the program can be released
to the public or other users (or to the
instructor of this class)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Implementation
 It is the process of installing the software
developed on customer‟s site.
 Installation may be done by replace the
entire manual work with the software
developed or in a pilot mode i.e. running
the manual and automated system in
parallel or installing only a part module
with manual work.
 It also involves training of software to the
intended users.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Documentation
- Contains details produced at all stages of the
program development cycle.
Can be done in 2 ways
* writing comments between your line of
codes.
* Creating a separate text file to explain the
program.
- Important not only for other people to use or
modify your program, but also for you to
understand your own program after along time.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Algorithm Watch on YouTube

 An algorithm is a list of steps to be executed with


the right order in which these steps should be
executed.
 According to D.E. Knuth, an algorithm has the
following characteristics:
An algorithm has fixed number of steps.
Each step in an algorithm specifies the action to
be performed.
The steps in an algorithm specify basic
operations.
An algorithm accepts input data.
An algorithm generates one or more outputs
after the input is processed
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Algorithm to withdraw money from ATM


The algorithm to withdraw a required amount from an ATM will
be:
1. Start the algorithm.
2. Go to any local ATM.
3. Insert/swipe your ATM card.
4. Press the language button that you want to choose.
5. Enter the pin code number.
6. Press the account type (Savings or Current) button from which you
want to withdraw the money.
7. Press the cash withdrawal button.
8. Enter the amount you want to withdraw.
9. Collect the amount from the ATM machine.
10. Collect the statement from the ATM machine.
11. Collect your ATM card.
12. End the algorithm.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Algorithm of getting out of bed and


prepare to go to work
1. Get out of Bed.
2. Take Shower.
3. Get Dressed

If a same steps are performed in a slightly


different order:
1. Get out of Bed.
2. Get Dressed.
3. Take Shower

What will be the result?


VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…
Write an algorithm to accept two numbers, divide the
first number by the second, and display their quotient.
Allocated time to solve the problem is 05 minutes.

Write an algorithm that accepts distance in kilometers,


converts it into meters, and then displays the result.
Hint: Distance in meters = Distance in kilometers * 1000
Allocated time to solve the problem is 05 minutes.

Write an algorithm that accepts five numbers and


displays the sum and average of the numbers.
Allocated time to solve the problem is 05 minutes.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Solution - 1
1. Start the algorithm.
2. Get the first number.
3. Get the second number.
4. Divide the first number by the
second.
5. Display the quotient.
6. End the algorithm. 72 9

72 9 8

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Solution - 2
1. Start the algorithm.
2. Get the distance in kilometers.
3. Multiply the distance by 1000.
4. Display the result of
multiplication as distance
in meters. 50
5. End the algorithm.
50 1000 50000

Distance in meters: 50000

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Solution - 3
1. Start the algorithm. 3
2. Get the first number. 1
3. Get the second number.
6 20
4. Get the third number.
2
5. Get the fourth number.
6. Get the fifth number. 8

7. Add the five numbers.


20 5 4
8. Divide the sum by 5.
9. Display the addition as sum Sum = 20
Average = 4
and result of division as average.
10. End the algorithm.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Flowchart
 Flowchart is a graph used to depict or
show a step by step solution using
symbols which represent a task.
 The symbols used consist of geometrical
shapes that are connected by flow lines.
 It is an alternative to pseudo coding,
where as a pseudo code description is
verbal. A flowchart is graphical in nature

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Advantages & Disadvantages of Flow Chart

ADVANTAGES
It helps in analyzing the problems effectively.
It acts as a guide during the program development phase.
It help easy debugging of logical errors

DISADVANTAGES
A lengthy flowchart may extend over multiple pages, which reduces
readability.
Drawing a flowchart is time consuming.
The changes made to a single step may cause redrawing the entire
flowchart

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Flowchart Symbols

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Flowchart Symbols

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Flowchart – To withdraw money from ATM


Start A

Go to any local ATM Press the cash withdrawal


button
Insert/swip
Enter the amount
e your card
that you want to
Press the language button withdraw
that you want to choose
Collect the amount
Enter the pin from the ATM machine
code number
Collect the statement
Press the account (Savings or Current)
from the ATM machine
button from which you want to
withdraw the money
Collect your ATM card
A
Stop
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Flowchart – To accept a number and


increment by 1, and display the result

Start

Accept a
number

Add 1 to the Number

Display the
number

Stop

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
Consider an example where you need to determine whether a
number is even or odd. This problem can be solved based on the
condition that the number should be divisible by 2. If the number is
divisible by 2, it should display the message, „The Number is Even‟,
otherwise „The Number is Odd‟.

Start

Accept a number

Divide the number by 2


Yes Display ‘The
Is the remainder
Number is
equal to zero ?
No Even’
Display ‘The
Number is Odd’

Stop

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a Minute…
 Write a flow chart to calculate area of
rectangle
◦ Allotted Time: 05 minutes
 Write a flow chart to enter any number
and check it is divisible by 7 or not
◦ Allotted Time: 05 minutes

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Solution - 1

Start

Accept length,
breadth

Area = length * breadth

Display Area

Stop

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Solution - 2
Start

Accept a number

Divide the number by 7

No
Display
Is the remainder ‘Number not
equal to zero ? divisible by
Yes 7’

Display ‘Number
divisible by 7’

Stop

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Pseudocode
 It is a formal way of writing the program logic
whereas algorithm is an informal way of writing
program logic
 It is detailed yet easy description of what algorithm
must do.
 It is written in formally styled-English language
 It is used as an initial step in the process of
developing of program
 Provide detailed template to programmers.
 It is language independent i.e. it can be converted
to program by using any programming language.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Pseudocode
 In Pseudocode we can use few special
words for determining the actions like
◦ Accept/input
◦ Display/print
◦ If / else
◦ Repeat
◦ Start
◦ End
◦ Goto
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example – to input 2 number and


display the sum
1. START
2. INPUT A, B
3. TOTAL = A + B
4. PRINT TOTAL
5. END

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example – to enter a number and


check it is even or odd
1. START MOD (%) is used to find out
remainder by dividing 2
2. INPUT NUM
3. IF NUM MOD 2 = 0 THEN
4. PRINT “NUMBER IS EVEN”
5. ELSE
6. PRINT “NUMBER IS ODD”
7. END

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Types of Control program structure


 In computer program there are mainly 3
types of control statements:
1. Sequential
2. Selection
3. Iteration

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Sequential
 A series of steps or statements that are executed
in a specific order.
 The beginning and end of a block of statements
can be optionally marked with the keywords
begin & end.
 Example:
1. Statement1
2. Statement 2
3. Statement 3
4. .
5. Statement n
 Here each statement will be executed one by one

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example – to swap 2 numbers


1. START In this Pseudocode, each
instruction will be executed one
by one without any jump
2. INPUT A, B
3. C =A Let us input A=10, B = 20
C = A ( C = 10 )
4. A=B A = B ( A = 20 )
B = C ( B = 10 )
5. B=C
We can clearly observe the
6. PRINT A,B values of A and B are
exchanged
7. END
Can you all think of another
method for the same problem
without using „C‟
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & Hint: use arithmetic operation
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Selection
 It determine two course of action depending
upon the condition.
 A condition is given here, which will result in
either True(1) or False (0)
 The keyword either if and else ( almost all
programming language also support this
keyword )
 It is also known as branching statement, because
it provide two branch, one for True and another
for False. Branching will be done depending
upon the condition.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example- to input age and check age


is eligible for voting or not
1. START
2. INPUT AGE
3. IF AGE>=18 THEN:
4. PRINT “ELIGIBLE FOR VOTING”
5. ELSE
6. PRINT “NOT ELIGIBLE FOR VOTING”
7. END
LET US TAKE INPUT IN AGE IS
29, THEN
IF AGE>=18 (TRUE) SO
OUTPUT WILL BE
“ELIGIBLE FOR VOTING”
NOW TAKE AGE=14
IF AGE>=18 (FALSE) SO
“NOT ELIGIBLE FOR
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & VOTING” WILL BE PRINTED
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Iteration
 It specifies block of one or more statement that
are repeatedly executed till condition remains
true.
 Keyword used are :
◦ While (supported by almost all programming language
also)
◦ If with go to (in Pseudocode only)
 Iteration consists of 3 main parts:
1. Initial value (from where iteration begins)
2. Condition (upto what condition iteration will continues)
3. Stepping (Increment/Decrement from Initial value to
reach to condition)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example: To print all number from


1 to 100 (While)
1. START
2. A=1 [INITIAL VALUE]

3. WHILE A<=100 [CONDITION]

4. PRINT A
5. A =A + 1 [INCREMENT]

6. END

Initially A =1, Now condition will be checked A<=100, will be true,


then it will print 1, now the value of A will be increment by 1 i.e.
becomes 2, now again condition will be checked, True, and this process
will be continued, After printing 100, value of A will become 101,
condition will be evaluated to False, and loop will end

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example: To print all number from


1 to 100 (if with go to)
1. START
2. A=1 [INITIAL VALUE]

3. PRINT A
4. A =A + 1
5. IF A<=100 THEN GO TO STEP 3
6. END

Initially A =1, It will print 1, after this value of A will be incremented


by 1 i.e. 2, Now the condition will be checked, A<=100 (2<=100) will
be true so execution will move to step 3 i.e. it will print 2 and again
incremented by 1 i.e. 3 and condition be will checked and printed, this
process will be condition, when value of A becomes 101, Pseudocode
will end

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a Minute….
1. Write a Pseudocode to convert temperature
in Fahrenheit to Celsius
2. Write a Pseudocode to input age and check
age is teenager or not
3. Write a Pseudocode to print all the even
numbers from 2 to 100
4. Write a Pseudocode to print all the odd
numbers from 100 to 1

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition
 Large program can be tackled with “divide and
conquer”.
 Decomposition happens when we break
down a problem into smaller parts so we can
both understand and manage
the problem better.
 For large, complex problems – we can then
analyze, solve and design the smaller parts of
the problem and then put it all together for a
solution.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Advantages
 Different people can work on different subprograms.
 Parallelization may be possible
 Maintenance is easier

Disadvantages
 The solution to subprogram might not combine to solve
the original problem
 Poorly understood problems are hard to decompose

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Need of Decomposition
 As studied earlier, first need of decomposition is
to divide the large program into smaller and
manageable sub program, it is easier to write 2
programs of 400 lines than writing single
program of 800 lines.
 Each subprogram can be managed
independently
 Global changes can be applied very easily
 Code can be reused
 Functions, modules, class are some example of
decomposition.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition Example - 1

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition Example - 2
LIBRARY MANAGEMENT

BOOKS MEMBERS ISSUE

ADD ADD BOOK ISSUE

EDIT EDIT BOOK RETURN

DELETE DELETE

SEARCH BOOK SEARCH MEMBER

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition Example - 3
 Think of a company creating a mobile phone.
Mobile phones are made up of lots of different
parts. Companies who make phones might
make a list of everything they need and
decompose the manufacturing process so that
one factory can be making the screens while
another makes batteries, another makes the
phone case and another makes mother board.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition – Developing a game


 Game designing is very complex process, it not very
simple. Playing game is a simple process but developing a
game is not the easy task.
 Step 1: Came up with an idea to develop a game
 Step 2: Create all the graphics required.
 Step 3: Record all the sound needed in game
 Step 4: Write code for each and every movement (run,
jump, sit, walk etc.), action(firing bullets, hit action etc.),
score calculation and so on.
 Step 5: Testing of Game
 Step 6: Debug and make improvements

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Decomposition – Developing a game

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Name derived from famous BBC


comedy show namely Monty
Python’s flying circus

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Python was created by Guido Van Rossum


The language was released in February I991
Python got its name from a BBC comedy series from seventies-
“Monty Python‟s Flying Circus”
Python can be used to follow both Procedural approach and
Object Oriented approach of programming
It is free to use
Python is based on or influenced with two programming
languages:
ABC language [replacement of BASIC]
Modula-3
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Easy to use Object oriented language


Expressive language
Interpreted Language
Its completeness
Cross-platform Language
Fee and Open source
Variety of Usage / Applications

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Python is compact and very easy to use object oriented


language with very simple syntax rules. It is very high level
language and thus very-very programmer -friendly

• More capable to express code‟s purpose than many othr


language like – swapping of two numbers:

In C++ In Python
int a=2, b=3, tmp; a,b=2,3
tmp=a; a,b=b,a
a=b;
b=tmp;
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• It is interpreted not compiled, thus executes code line by line


and it makes python easy-to-debug and suitable for beginners
and advanced users

• When you install Python, you get everything i.e. you don‟t need
to install additional libraries. All functionality is available with
Python additional library. Features like web-pages, database
connectivity, GUI features are available in Python standard
library. Python follows – “Battery included” philosophy

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Python can run equally well on variety of platforms – Windows,


Linux/UNIX, Macintosh, supercomputers, smart phones. Python is
portable language.

• It is feely available i.e. without any cost can be downloaded


from www.python.org.
• It is also open source i.e. you can modify, improve/extend an
open-source software

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Python is being used in many diverse


fields/applications, some of which are:
• Scripting
• Web Applications
• Game Development
• System Administrations
• Rapid Prototyping
• GUI Programs
• Database Applications

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Not the fastest language


Lesser Libraries than C, Java, Perl
Not Strong on Type-binding
Not Easily convertible

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Because of its interpreted nature Python is not fast as compare


to compiled language. Python is first compiled into an internal
byte-code which is then executed by Python interpreter.

• Python offers library support for almost all computing


programs, but its library is still not competent with languages
like C, java as they have larger collection available.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Python is not very strong on data type checking i.e. “Type-


mismatch” issues. For example if you declare variable as
integer but later store a string value in it, Python will not raise
any error.

• Because of its lack of syntax, Python is easy to program but it


becomes disadvantage when it comes to translate python
program to another language.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Before we start working on Python we need to install Python in our


computer. There are multiple distributions available today:

Default Installation available from www.python.org is called


Cpython installation and comes with python interpreter, Python
IDLE(Python GUI) and Pip(package installer)
ANACONDA Python distribution is one such highly
recommended distribution that comes with preloaded many
packages and libraries(NumPy, SciPy, Panda etc)
Other Popular IDEs like Sypder, PytCharm, etc. Spyder IDE is
available as a part of ANACONDA.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

After Python installation we can start working with python. In


Python we can work in 2 ways:

Interactive Mode
(Immediate
Python working Mode)
Ways
Script Mode

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

The default installation of CPython comes with Python


Interpreter, Python IDLE and pip(package installer). To work in
either interactive mode or script we need to open Python
IDLE
To work in interactive mode, follow the process given below:
(i) Click start button  All Programs  Python 3.6.x IDLE
Or
Click start button  All Programs  Python 3.6.x Python
(command line)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Interactive modes – one command at a time


Python executes the given command and gives the output.
In interactive mode we type command at IDLE prompt ( >>> )
For e.g if you type 20 + 30 in from of IDLE prompt
>>> 20 + 30 (command give by user)
50 (output given by python)
From the above example you can see than at >>> we have to
just give the command to execute and python we execute it if it
is error free otherwise gives an error.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

( )
( )
( )
( )

( )
print (“Hello”)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Script Mode – multiple commands can be saved in a file as a


program and then we can execute the entire program
we type Python program in a file and then use the interpreter
to execute the content from the file.
Working in interactive mode is convenient for beginners and for
testing small pieces of code, as we can test them immediately.
But for coding more than few lines, we should always save our
code so that we may modify and reuse the code

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

In Python IDLE :


Click File  New
In new window type the commands you want to save in program
For example:
print(“Hello World!”)

FileSave to save file. Give extension .py to execute it as


python script

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Save the
program
and press
F5
( )
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Type the below code in script file:

#My First Program


print(“Hello World!”)

When you execute the script file output will be only


Hello World
Note: the first line starts from # which makes line as a
comment i.e. only for programmer information not for
interpreter. Comments are ignored by interpreter
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

To print or display output Python 3.x provides print() function.


Examples:-
print(“Welcome to Python”)
it will print Welcome to Python
print(„Python rocks!‟)
it will print Python rocks!
Note: Python allows both single quotation and double quotation
to enclose string. In any case both opening and closing must be
same.
print(„Look carefully”)
it will give error because both opening and closing
quotes are different.VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Note:
1) In Python 2.x print is a statement, not a function
2) Python is case-sensitive i.e. it will treat small letter and
capital letter as two different entities like m & M will be
treated differently in Python.
3) We can use up arrow (↑) and down arrow (↓) to select
previous command and press enter to recall and execute.
4) print statement is required only while working with
script mode otherwise in interactive mode values can be
printed without print statement
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

#This is my first program


#sample of basic statements
#print(“Watch out”)
print(“Johny Johny Yes Papa”)
print(“No Papa”)
(a) (b)
This is my first program sample of basic Watch out
statements Watch out Johny Johny Yes Papa
Johny Johny Yes Papa No Papa
No Papa

(c) (d)
Johny Johny Yes Papa This is my first program
No Papa Johny Johny Yes Papa
No PapaLittle Star
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

(a) “Sayonara” (b) „Sayonara‟


(c) “Sayonara‟ (d) „Sayonara”
(e) {Sayonara}

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

• Who developed Python Programming Language?


• Is Python Object Oriented Language?
• Python is a high level interpreted language. What does it means
• What does cross-platform means?
• Python is free and open source. What do you understand by
this feature?
• What is the difference in interactive mode and Script mode in
Python?

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

PYTHON FUNDAMENTALS
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR
& SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Python Character Set


Is a set of valid characters that python can recognize. A
character represent letters, digits or any symbol. Python
support UNICODE encoding standard. Following are the
Python character set
 Letters : A-Z, a-z
 Digits : 0-9
 Special symbols :space +-*/()~`!@#$%^ & [{
]};:‟”,<.>/?
 White spaces : Blank space, Enter, Tab
 Other character : python can process all ASCII and
UNICODE as a part of data or literal

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

TOKENS
In a passage of text, individual words and punctuation
marks are called tokens or lexical units or lexical
elements. The smallest individual unit in a program is
known as Tokens. Python has following tokens:

 Keywords
 Identifiers(Name)
 Literals
 Operators
 Punctuators
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

KEYWORDS
Keywords are the reserved words and have special
meaning for python interpreter. Every keyword is
assigned specific work and it can be used only for that
purpose.
A partial list of keywords in Python is

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

IDENTIFIERS
Are the names given to different parts of program like variables,
objects, classes, functions etc.
Identifier forming rules of Python are :

 Is an arbitrarily long sequence of letters and digits


 The first character must be letter or underscore
 Upper and lower case are different
 The digits 0-9 are allowed except for first character
 It must not be a keyword
 No special characters are allowed other than underscore is allowed.
 Space not allowed

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

The following are some valid identifiers


GradePay File_12_2018 JAMES007
GRADEPAY _ismarried _to_update

The following are some invalid identifiers

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & SACHIN


BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Literals / Values
 Literals are data items that have a fixed value.
Python supports several kinds of literals:
 String Literal
 Numeric Literals

 Boolean Literals

 Special Literals – None

 Literal Collections

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

String Literals
 It is a collection of character(s) enclosed in a double or
single quotes
 Examples of String literals
 “Python”
 “Mogambo”
 „123456‟
 „Hello How are your‟
 „$‟, „4‟,”@@”
 In Python both single character or multiple characters
enclosed in quotes such as “kv”, „kv‟,‟*‟,”+” are treated
as same

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Non-Graphic (Escape) characters


 They are the special characters which cannot be
type directly from keyboard like backspace, tabs,
enter etc. When the characters are typed they
perform some action. These are represented by
escape characters. Escape characters are always
begins from backslash(\) character.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

List of Escape characters


Escape Sequence What it does Escape Sequence What it does
\\ Backslash \r Carriage return
\‟ Single quotes \t Horizontal tab
\” Double quotes \uxxxx Hexadecimal
value(16 bit)
\a ASCII bell \Uxxxx Hexadecimal
value(32 bit)
\b Back Space \v vertical tab
\n New line \ooo Octal value

Watch Demo on YouTube

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

String type in Python


 Python allows you to have two string types:
 Single Line Strings
 The string we create using single or double quotes are
normally single-line string i.e. they must terminate in one line.
 For e.g if you type as
 Name="KV and press enter
 Python we show you an error “EOL while scanning string literal”
 The reason is quite clear, Python by default creates single-line
string with both single quotes and it must terminate in the same
line by quotes

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

String type in Python


 Multiline String
 Some times we need to store some text across multiple
lines. For that Python offers multiline string.
 To store multiline string Python provides two ways:
(a) By adding a backslash at the end of normal Single / Double
quoted string. For e.g.
>>> Name="1/6 Mall Road \
Kanpur"
>>> Name
'1/6 Mall RoadKanpur'
>>>
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

String type in Python


 Multiline String
(b) By typing text in triple quotation marks
for e.g.
>>> Address="""1/7 Preet Vihar
New Delhi
India"""
>>> print(Address)
1/7 Preet Vihar
New Delhi
India
>>> Address
'1/7 Preet Vihar\nNew Delhi\nIndia'

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Size of String
 Python determines the size of string as the count of characters in the string.
For example size of string “xyz” is 3 and of “welcome” is 7. But if your
string literal has an escape sequence contained in it then make sure to count
the escape sequence as one character. For e.g.

String Size
„\\‟ 1
„abc‟ 3
„\ab‟ 2
“Meera\‟s Toy” 11
“Vicky‟s” 7
 You can check these size using len() function of Python. For example
 >>>len(„abc‟) and press enter, it will show the size as 3

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Size of String
 For multiline strings created with triple quotes : while calculating size
the EOL character as the end of line is also counted in the size. For
example, if you have created String Address as:
>>> Address="""Civil lines
Kanpur"""
>>> len(Address)
18
 For multiline string created with single/double quotes the EOL is not
counted.
>>> data="ab\
bc\
cd"
>>> len(data)
6
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Numeric Literals
 The numeric literals in Python can belong to any of
the following numerical types:
1) Integer Literals: it contain at least one digit and must
not contain decimal point. It may contain (+) or (-) sign.
 Types of Integer Literals:
a) Decimal : 1234, -50, +100
b) Octal : it starts from symbol 0o (zero followed by
letter ‘o’)
 For e.g. 0o10 represent decimal 8

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Numeric Literals
>>> num = 0o10
>>> print(num)
It will print the value 8

c) Hexadecimal : it starts from 0x (zero followed by


letter ‘x’)
>>> num = 0oF
>>> print(num)
it will print the value 15

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Numeric Literals
 2) Floating point Literals: also known as real
literals. Real literals are numbers having fractional
parts. It is represented in two forms Fractional Form
or Exponent Form
 Fractional Form: it is signed or unsigned with decimal point
 For e.g. 12.0, -15.86, 0.5, 10. (will represent 10.0)
 Exponent Part: it consists of two parts “Mantissa” and
“Exponent”.
 For e.g. 10.5 can be represented as 0.105 x 102 = 0.105E02 where
0.105 is mantissa and 02 (after letter E) is exponent

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Points to remember
 Numeric values with commas are not considered int or float value, rather Python
treats them as tuple. Tuple in a python is a collection of values or sequence of values.
(will be discussed later on)
 You can check the type of literal using type() function. For e.g.
>>> a=100
>>> type(a)
<class 'int'>
>>> b=10.5
>>> type(b)
<class 'float'>
>>> name="hello“
>>> type(name)
<class 'str'>
>>> a=100,50,600
>>> type(a)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & <class 'tuple'>
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Boolean Literals
A Boolean literals in Python is used to represent one of the two
Boolean values i.e. True or False
These are the only two values supported for Boolean Literals
For e.g.

>>> isMarried=True
>>> type(isMarried)
<class 'bool'>

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Special Literals None


Python has one special literal, which is None. It indicate absence
of value. In other languages it is knows as NULL. It is also used
to indicate the end of lists in Python.

>>> salary=None
>>> type(salary)
<class 'NoneType'>

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Complex Numbers
Complex: Complex number in python is made up of two floating point values,
one each for real and imaginary part. For accessing different parts of
variable (object) x; we will use x.real and x.image. Imaginary part of the
number is represented by “j” instead of “I”, so 1+0j denotes zero imaginary.
part.
Example
>>> x = 1+0j
>>> print x.real,x.imag
1.0 0.0
Example
>>> y = 9-5j
>>> print y.real, y.imag
9.0 -5.0
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Conversion from one type to another


Python allows converting value of one data type to another data
type. If it is done by the programmer then it will be known as type
conversion or type casting and if it is done by compiler automatically
then it will be known as implicit type conversion.
Example of Implicit type conversion
>>> x = 100
>>> type(x)
<type 'int'>
>>> y = 12.5
>>> type(y)
<type 'float'>
>>> x=y
>>> type(x)
<type 'float'> # Here x is automatically converted to float
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Conversion from one type to another


Explicit type conversion
To perform explicit type conversion Python provide functions like
int(), float(), str(), bool()
>>> a=50.25
>>> b=int(a)
>>> print b
50
Here 50.25 is converted to int value 50
>>>a=25
>>>y=float(a)
>>>print y
25.0
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Simple Input and Output


 In python we can take input from user using the built-in function
input().
 Syntax
variable = input(<message to display>)
Note: value taken by input() function will always be of String type, so by
default you will not be able to perform any arithmetic operation on variable.
>>> marks=input("Enter your marks ")
Enter your marks 100
>>> type(marks)
<class 'str'>
Here you can see even we are entering value 100 but it will be treated as
string and will not allow any arithmetic operation
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Simple Input and Output


>>> salary=input("Enter your salary ")
Enter your salary 5000
>>> bonus = salary*20/100
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'int'

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Reading / Input of Numbers


 Now we are aware that input() function value will
always be of string type, but what to do if we want
number to be entered. The solution to this problem is
to convert values of input() to numeric type using int()
or float() function.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Possible chances of error while taking


input as numbers
1. Entering float value while converting to int
>>> num1=int(input("Enter marks "))
Enter marks 100.5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '100.5‘

2. Entering of values in words rather than numeric


>>> age=int(input("What is your age "))
What is your age Eighteen
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: Eighteen'
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Possible chances of error while taking


input as numbers
3. While input for float value must be compatible. For e.g.
Example 1
>>> percentage=float(input("Enter percentage "))
Enter percentage 12.5.6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '12.5.6'

Example 2
>>> percentage=float(input("Enter percentage "))
Enter percentage 100 percent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: „100 percent'
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Program 1
Open a new script file and type the following code:

num1=int(input("Enter Number 1 "))


num2=int(input("Enter Number 2 "))
num3 = num1 + num2
print("Result =",num3)

Save and execute by F5 and observe the result


VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Let us write few programs


 WAP to enter length and breadth and calculate area
of rectangle
 WAP to enter radius of circle and calculate area of
circle
 WAP to enter Name, marks of 5 subject and calculate
total & percentage of student
 WAP to enter distance in feet and convert it into inches
 WAP to enter value of temperature in Fahrenheit and
convert it into Celsius.
 WAP to enter radius and height of cylinder and
calculate volume of cylinder.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Operators
 are symbol that perform specific operation when
applied on variables. Take a look at the expression:
(Operator)
10 + 25 (Operands)
Above statement is an expression (combination
of operator and operands)
i.e. operator operates on operand. some operator requires two
operand and some requires only one operand to operate

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Types of Operators
 Unary operators: are those operators that require
one operand to operate upon. Following are some
unary operators:

Operator Purpose
+ Unary plus
- Unary minus
~ Bitwise complement
Not Logical negation
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Types of Operators
 Binary Operators: are those operators that require two
operand to operate upon. Following are some Binary
operators:
1. Arithmetic Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder
** Exponent
// Floor division
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example
>>> num1=20
>>> num2=7
>>> val = num1 % num2
>>> print(val)
6
>>> val = 2**4
>>> print(val)
16
>>> val = num1 / num2
>>> print(val)
2.857142857142857
>>> val = num1 // num2
>>> print(val)
2

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Bitwise operator
Operator Purpose Action
Bitwise operator works
& Bitwise AND Return 1 if both on the binary value of
inputs are 1 number not on the actual
^ Bitwise XOR Return 1, if the value. For example if 5
number of 1 in is passed to these
input is in odd operator it will work on
101 not on 5. Binary of
| Bitwise OR Return 1 if any 5 is 101, and return the
input is 1 result in decimal not in
binary.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Example
Binary of 12 is 1100 and 7 is 0111, so applying &
1100
0111
-------
Guess the output with
0100 Which is equal to decimal value 4
| and ^ ?

Let us see one practical example, To check whether entered number is divisible of 2 (or in
a power of 2 or not) like 2, 4, 8, 16, 32 and so on
To check this, no need of loop, simply find the bitwise & of n and n-1, if the result is 0 it
means it is in power of 2 otherwise not

Here we can see


Later on by using „if‟ we can print Here we can see 0,
16, it means 24 is
it means 32 is in
meaningful message power of 2 not in power of 2
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Operators Purpose
<< Shift left
>> Shift right

Identity Operators
Operators Purpose
is Is the Identity same?
is not Is the identity not same?
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Relational Operators
Operators Purpose
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
!= Not equal to

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Logical Operators
Operators Purpose
and Logical AND
or Logical OR
not Logical NOT

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Assignment Operators
Operators Purpose
= Assignment
/= Assign quotient
+= Assign sum
-= Assign difference
*= Assign product
**= Assign Exponent
//= Assign Floor division

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Membership Operators
Operators Purpose
in Whether variable in
sequence
not in Whether variable not in
sequence

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Punctuators
 Punctuators are symbols that are used in programming
languages to organize sentence structure, and indicate
the rhythm and emphasis of expressions, statements,
and program structure.
 Common punctuators are: „ “ # $ @ []{}=:;(),.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Barebones of Python Program


 It means basic structure of a Python program
 Take a look of following code:

#This program shows a program‟s component


# Definition of function SeeYou() follows
def SeeYou(): Comments
print(“This is my function”)
#Main program Function
A=10
B=A+20
Statements

C=A+B Expressions
Inline Comment
if(C>=100) #checking condition
print(“Value is equals or more than 100”)
else:
print(“Value is less than 100”) Block
Indentation

SeeYou() #Calling Function

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Expression
 An expression is any legal combination of symbols that
represents a value. An expression is generally a
combination of operators and operands
Example:
expression of values only
20, 3.14
Expression that produce a value when evaluated
A+10
Salary * 10 / 100

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Statement
 It is a programming instruction that does something i.e.
some action takes place.
 Example

print(“Welcome to python”)
The above statement call print function
When an expression is evaluated a statement is executed
i.e. some action takes place.
a=100
b = b + 20
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Comments
 Comments are additional information written in a
program which is not executed by interpreter i.e.
ignored by Interpreter. Comment contains information
regarding statements used, program flow, etc.
 Comments in Python begins from #

 Python supports 3 ways to enter comments:

1. Full line comment


2. Inline comment
3. Multiline comment
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Comments
 Full line comment
Example:
#This is program of volume of cylinder
 Inline comment

Example
area = length*breadth # calculating area of rectangle
 Multiline comment

Example 1 (using #)
# Program name: area of circle
# Date: 20/07/18
#Language : Python
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Comments
Multiline comment (using “ “ “) triple quotes
Example
“““
Program name : swapping of two number
Date : 20/07/18
Logic : by using third variable
”””

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Functions
Function is a block of code that has name and can be
reused by specifying its name in the program where
needed. It is created with def keyword.
Example
def drawline():
print(“======================“)
print(“Welcome to Python”)
drawline()
print(“Designed by Class XI”)
drawline()
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Block and Indentation


 Group of statement is known as block like function,
conditions or loop etc.
 For e.g.

def area():
a = 10
b=5
c=a*b
Indentation means extra space before writing any
statement. Generally four space together marks the next
indent level.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Variables
 Variables are named temporary location used to store
values which can be further used in calculations, printing
result etc. Every variable must have its own Identity, type
and value. Variable in python is created by simply
assigning value of desired type to them.
 For e.g
 Num = 100
 Name=“James”

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Variables
 Note: Python variables are not storage containers like other
programming language. Let us analyze by example.
 In C++, if we declare a variable radius:

radius = 100
[suppose memory address is 41260]
Now we again assign new value to radius
radius = 500
Now the memory address will be still same only value
will change
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Variables
 Now let us take example of Python:
radius = 100 [memory address 3568]

radius = 700 [memory address 8546]

Now you can see that In python, each time you assign new
value to variable it will not use the same memory address
and new memory will be assigned to variable. In python the
location they refer to changes every time their value
change.(This rule is not for all types of variables)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Lvalues and Rvalues


 Lvalue : expression that comes on the Left hand Side of
Assignment.
 Rvalue : expression that comes on the Right hand Side of
Assignment

Lvalue refers to object to which you can assign value. It refers to


memory location. It can appear LHS or RHS of assignment

Rvalue refers to the value we assign to any variable. It can


appear on RHS of assignment

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Lvalues and Rvalues


For example (valid use of Lvalue and Rvalue)
x = 100
y = 200

Invalid use of Lvalue and Rvalue


100 = x
200 = y
a+b = c

Note: values cannot comes to the left of assignment. LHS must be a


memory location

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiple Assignments
 Python is very versatile with assignments. Let‟s see in how different ways
we can use assignment in Python:
1. Assigning same value to multiple variable
a = b = c = 50
2. Assigning multiple values to multiple variable
a,b,c = 11,22,33

Note: While assigning values through multiple assignment, remember that


Python first evaluates the RHS and then assigns them to LHS

Examples:

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiple Assignments
x,y,z = 10,20,30 #Statement 1
z,y,x = x+1,z+10,y-10 #Statement 2
print(x,y,z)
Output will be
10 40 11
Now guess the output of following code fragment
x,y = 7,9
y,z = x-2, x+10
print(x,y,z)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Multiple Assignments
Let us take another example

y, y = 10, 20

In above code first it will assign 10 to y and again it assign 20


to y, so if you print the value of y it will print 20

Now guess the output of following code


x, x = 100,200
y,y = x + 100, x +200
print(x,y)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Variable definition
 Variable in python is create when you assign value to it
i.e. a variable is not create in memory until some value is
assigned to it.
 Let us take as example(if we execute the following code)

print(x)
Python will show an error „x‟ not defined
So to correct the above code:
x=0
print(x) #now it will show no error
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Dynamic Typing
 In Python, a variable declared as numeric type can be
further used to store string type or another.
 Dynamic typing means a variable pointing to a value of
certain type can be made to point to value/object of
different type.
 Lets us understand with example
x = 100 # numeric type
print(x)
x=“KVians” # now x point to string type
print(x)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Dynamic Typing

x=10 x int: 100


0
x=“KVians” x int:100

string:KVians

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & SACHIN


BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Caution with Dynamic Typing


 Always ensure correct operation during dynamic typing.
If types are not used correctly Python may raise an
error.
 Take an example

x = 100
y=0
y=x/2
print(y)
x='Exam'
y = x / 2 # Error, you cannot divide string
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Determining type of variable


Python provides type() function to check the datatype of
variables.
>>> salary=100
>>> type(salary)
<class 'int'>
>>> salary=2000.50
>>> type(salary)
<class 'float'>
>>> name="raka"
>>> type(name)
<class 'str'>
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()

 Python allows to display output using print().


 Syntax:
print(message_to_print[,sep=“string”,end=“string”])
Example 1
print(“Welcome”)
Example 2
Age=20
print(“Your age is “, Age)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Example 3
r = int(input("Enter Radius "))
print("Area of circle is ",3.14*r*r)

Note: from the Example 2 and Example 3 we can


observe that while printing numeric value print() convert
it into equivalent string and print it. In case of expression
(Example 3) it first evaluate it and then convert the result
to string before printing.

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Note:
print() automatically insert space between different values
given in it. The default argument of sep parameter of
print() is space(‘ ‘) .
Example
print(“Name is”,”Vicky”)
Output
Name is Vicky

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Note:
Python allows to change the separator string.
Example
print(“Name is”,”Vicky”,”Singh”,sep=“##”)
Output
Name is ##Vicky##Singh

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Note:
Be default each print statement print the value to next
line. The default value of end is “\n”
Example
print(“Learning Python”)
print(“Developed by Guido Van Rossum”)
Output
Learning Python
Developed by Guido Van Rossum

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Note:
We can change the value of end to any other value.
Example
print(“Learning Python”,end=“ “)
print(“Developed by Guido Van Rossum”)
Output
Learning Python Developed by Guido Van Rossum

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Output through print()


Can you Guess the output
Name=“James”
Salary=20000
Dept=“IT”
print(“Name is “,Name,end=“@”)
print(Dept)
print(“Salary is “,Salary)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…
 What is the difference between keywords and
identifiers
 What are literals in Python? How many types of

literals in python?
 What will be the size of following string

„\a‟ , “\a” , “Reena\‟s”, „\”‟, “It‟s”, “XY\ , “ “ “XY


YZ” YZ”””
 How many types of String in python?

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…

 What are the different ways to declare multiline String?


 Identify the type of following literal:

41.678, 12345, True, „True‟, “False”, 0xCAFE, 0o456,0o971


 Difference between Expression and Statement

 What is the error inn following python program:

print(“Name is “, name)

Suggest a solution
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…

 Which of the following string will be the syntactically


correct? State reason.
1. “Welcome to India”
2. „He announced “Start the match” very loudly‟
3. “Sayonara‟
4. „Revise Python Chapter 1‟
5. “Bonjour
6. “Honesty is the „best‟ policy”

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…

 The following code is not giving desired output. We


want to enter value as 100 and obtain output as 200.
Identify error and correct the program

num = input("enter any number")


double_num = num * 2
Print("Double of",num,"is",double_num)

VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &


SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…

 Why the following code is giving error?

Name="James"
Salary=20000
Dept="IT"
print("Name is ",Name,end='@')
print(Dept)
print("Salary is ",Salary)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com

Just a minute…

 WAP to obtain temperature in Celsius and convert it into


Fahrenheit. F = 9*C/5 + 32
What will be the output of following code:
x, y = 6,8
x,y = y, x+2
print(x,y)
 What will be the output of following code:

x,y = 7,2
x,y,x = x+4, y+6, x+100
print(x,y)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR

You might also like