Class Xi Term-1 Study Material
Class Xi Term-1 Study Material
● Hardware are physical components which can be seen and touched (tangible). Examples of
hardware include CPU, mouse, keyboard, monitor, motherboard, cables, CPU case, power supply
unit, RAM, graphics card, sound card etc.
● Various hardware components are interconnected together using a pathway called 'Bus', that
facilitates the transfer of data.
● Software is a set of instructions, its documentation and data, which are stored digitally on the
computer. Examples are Microsoft Windows, Linux, Paint, Word, PowerPoint, Photoshop, VLC
Media Player, VS Code, Python. The software is intangible, i.e cannot be touched.
● A computer system receives instructions from the user (usually a human) using Input Devices.
● The Operating System (OS) is a crucial piece of software that allows users to interact with the
computer hardware and other software easily.
● Computers process data through a series of instructions stored in their memory. The CPU fetches
these instructions, decodes them, and then executes them.
● Computers can talk to other computers through networking. The Internet is one such network.
Advantages of Computers
● Multi-tasking - can perform multiple tasks simultaneously
● Speed - computes data rapidly
● Productivity - automates and streamlines work process to increase productivity
● Accuracy - tasks are performed with high accuracy
● Connectivity - access to vast amount of data and global communication networks
● Education- enhances learning through stores resources
● Storage - can store large amounts of data for a long time
● Reliability - can perform its functions adequately in a controlled environment with high precision
Disadvantages of Computers
● High initial costs of purchase, maintenance
3
● Long use may lead to health issues
● Security Risks - vulnerable to hacking, loss and theft of information
● Environmental Impact due to high carbon emissions
● Software issues - problems may arise due to buggy software
4
Input Devices
● The hardware devices that send input data from the user to the CPU are known as Input Devices.
● They are responsible for capturing, and transferring data from the outside world into the computer
system.
● Some of the popular Input Devices are Keyboard, Mouse, Joystick, Scanner, Microphone,
Touchpad, Biometric Sensors, Graphic Tablet, Bar/QR Code Readers, Webcam, Magnetic Ink
Character Reader (MICR) and Optical Character Reader (OCR) devices etc.
Output Devices
1. The hardware devices that are responsible for displaying output from the computer are known
as Output Devices.
2. Some of the popular Output Devices are Display Monitor, Projector, Speaker, Printer, Plotter,
Headphones etc
5
7. Registers can be accessed in a single CPU instruction and thus are extremely fast storage.
8. Registers are limited in number and thus data has to be transferred from the main/cache memory to
the registers for processing of data.
Memory
1. The location where the computer stores data, instructions, and programs is called the Memory.
2. Computer memory is organized into memory cells, each of which stores a fixed amount of data,
typically represented in binary as 0s and 1s.
3. The Memory of a computer is divided into Primary, Cache and Secondary Memory.
Primary Memory
1. The primary memory is directly accessible by the CPU.
2. It is a high speed memory which can closely match the operational speed of the CPU.
6
3. Due to the high speed, the cost of primary memory is high and the storage capacity of primary
memory is lower in comparison to the secondary memory.
4. There are two kinds of primary memory, namely RAM and ROM.
Cache Memory
1. Cache memory is an intermediate memory between the CPU and the primary memory.
2. The need for cache memory arises from the difference in operational speed of the CPU and the
primary memory.
7
3. Often, the CPU is faster than the RAM/ main memory, and thus has to wait for the next instruction
to be loaded from the memory.
4. To reduce this waiting time, and increase the throughput of the CPU, a cache memory (buffer) is
placed between the CPU and primary memory.
5. The cache holds frequently used instructions and data and makes them readily available to the CPU.
Secondary Memory
1. Secondary memory is also known as permanent memory.
2. It is non-volatile in nature, i.e the data does not get lost even after power is turned off from the
computer.
3. Examples of Secondary memory are Hard Disk Drive, Solid State Drive, USB Flash Drive.
4. The CPU does not interact with the Secondary Memory directly.
Units of Memory
1. The smallest unit of memory is called a binary digit, or a bit.
2. The bit can assume only two values, 0 and 1.
3. A sequence of 4-bits is called a Nibble.
4. A Word is a fixed length sequence of bits which the processor can handle at a time.
3 Word Group of bits on which the CPU can work as a single unit. Can be
8 bits, 16 bits, 32 bits or 64 bits depending on CPU Architecture.
5 KiloByte(KB) 1 KB = 1024 B
6 MegaByte(MB) 1 MB = 1024 KB
7 GigaByte(GB) 1 GB = 1024 MB
8 TeraByte(TB) 1 TB = 1024 GB
9 PetaByte(PB) 1 PB = 1024 TB
8
Types of Software
System Software
It is software which controls all the operations of the computer system and interacts with the hardware
connected to the computer. The computer cannot operate without system software. System software is
majorly categorized into: Operating System, System Utilities and Device Drivers.
Operating System
An operating system is system software that acts as an interface between the user and the computer hardware
and manages all the resources of a computer. Examples of operating systems are Microsoft Windows,
Ubuntu, Android, Apple iOS etc.
System Utilities
The software that performs maintenance and configuration of the computer system is called
System Utility.
Examples include Antivirus software, Disk Defragmentation Tool, System Restore Utility, Disk
Partitioning Utility etc.
Device Drivers
The software that directly interacts with a particular hardware or peripheral device is called the device
driver. Each hardware has its unique device driver without which the operating system cannot communicate
with the device. Examples include RealTek Audio Driver, NVidia Video Driver, MS USB
Driver etc.
9
Language Translators
Languages are majorly divided into two categories: Low Level Languages and High-Level Languages.
● Low Level Languages are nearer to Machine Code than to human-like languages. They are difficult
to understand by humans but easily understandable by machines.
● On the other hand, humans can easily understand high level languages but computers require
language translators to convert high level languages into low level languages which they understand.
● Low level language comprises Binary Language (combination of 0’s and 1’s) and Assembly
Language (uses keywords like ADD, SUB, STR), whereas High Level Language comprises C, C++,
Java, Python etc.
● Software that translates one language to another language is called language translators.
● Language Translators can be divided into Compiler, Interpreter and Assembler.
Programming Tools
Tools that assist the users/developers in creating, editing, testing and debugging related to the development
of software are known as Programming Tools.
They support completion of tasks during the development phase. It includes development tools, code editors
and translators.
Examples include : Visual Studio Code, Sublime Text, Eclipse etc.
Operating System
An operating system is system software that acts as an interface between the user and the computer hardware
and manages all the resources of a computer.
10
Examples of Operating System
11
Memory Management
The operating system manages the memory resources of a computer system. It keeps a record of used and
available memory. It includes:
Device Management
Operating system manages communication among all the devices, keeps track of all the devices, allocates
and deallocates devices. It includes:
● Device initialization
● Device Configuration
● Device Scheduling
Process Management
It manages all the programs in execution (processes). It includes:
File Management
The operating system manages all the file management tasks. It keeps track of location, status, storage and
operations of a file. It includes:
Network Management
It provides services to organize and maintain the network. It allows computers in a network to communicate
with each other. It includes:
● Network Configuration
● Network Connectivity
● Network Resource Management
12
Security
The operating system protects the system from all the threats, unauthorized access and other vulnerabilities.
It includes:
● Authentication
● Authorization
● Data Encryption
● Firewall Management
Other tasks
Some other tasks performed by OS are Job Accounting, Error Detection, Control over System Performance,
Resource Allocation, Information and Resource Protection, and Handling I/O Operations.
OS User Interface
Operating system acts as an interface between the user and the hardware. There are types of interfaces to
perform different tasks on the basis of requirement.
13
Boolean Logic
Boolean Logic is a concept that involves binary variables and operations. It focuses on the values true and
false (1 and 0). It was developed by the English Mathematician and logician George Boole. Boolean Algebra
comprises of following:
1. Boolean Expression
2. Boolean Variable
Boolean Variable
A boolean variable is a variable that holds boolean values True/ False or 1/0.
Boolean Expression
A boolean expression is an expression that consists of a combination of boolean variables, boolean values
and boolean operators. A boolean expression evaluates to either True or False.
Boolean Operators
Boolean operators perform operations on operands (Boolean Variables/Values). The boolean operators are:
AND, OR and NOT.
AND operator - It evaluates to True(1) if all inputs are True(1), otherwise False(0). It is represented by the
dot operator (.)
Example : A.B may be read A AND B
OR operator - It evaluates to True(1) if any of the inputs is True(1), otherwise False(0). It is represented by
the + operator.
Example: A + B may be read as A OR B.
NOT operator - It evaluates to True(1) when the condition is False, and returns False(0) when the condition
is True(1).
Truth Table
A truth table is a representation of all possible combinations of the input variables and the corresponding
output values.
The number of rows in a truth table are 2n, where n is no. of input variables.
Example- Here, A and B are the input boolean variables, OR (+) is the operator, F is the output.
14
A B F = A OR B
0 0 0
0 1 1
1 0 1
1 1 1
De Morgan’s Laws
DeMorgan’s First Law states that when two input variables are AND’ed and complemented, they are
equivalent to the OR of the complements of the individual variables.
(AB)'=A'+B'
0 0 1 1 0 1 1
0 1 1 0 0 1 1
1 0 0 1 0 1 1
1 1 0 0 1 0 0
15
DeMorgan’s Second Law states that when two input variables are OR’ed and complemented, they are
equivalent to the AND of the complements of the individual variables.
(A+B)'=A'.B'
0 0 1 1 0 1 1
0 1 1 0 1 0 0
1 0 0 1 1 0 0
1 1 0 0 1 0 0
Logic Gates
A logic gate is a device that performs a Boolean Function. One or more inputs in the form of 1/0 are provided
to get the specific output governed by a logic. Examples of Logic Gates are: AND, OR, NOT, NOR, NAND
and XOR.
NAND and NOR are called Universal Gates, as they can implement any Boolean expression.
AND Gate
Truth Table
A B A.B
0 0 0
0 1 0
1 0 0
1 1 1
16
OR Gate
Truth Table
A B A+B
0 0 0
0 1 1
1 0 1
1 1 1
NOT Gate
Truth Table
A A'
0 1
1 0
NAND Gate
Logic Gate Diagram
Truth Table
17
NOR Gate
A B A+B (A+B)'
0 0 0 1
0 1 0 1
1 0 0 1
1 1 1 0
Truth Table
XOR Gate
Truth Table
A B A⊕B
0 0 0
0 1 1
1 0 1
1 1 0
18
Logic Circuits
A logic circuit is an electronic circuit which performs logical operations on the input boolean variables, and
transforms them into the output using a combination of Logic Gates.
Y=(A.B)’BC’
Y Y=?
Number System
There are many possible ways to represent numbers. A number system provides a consistent and unique
method to represent the numbers.
A positional number system is one way of writing numbers. It has unique symbols for 0 through (b – 1),
where b is the base (also known as radix) of the system. These symbols are called digits.
19
Decimal Number System
A decimal number uses base-10 for representing numbers. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 are the
digits present in the system. Every number can be represented as a sum of powers of 10, with each power
weighted by a digit.
The binary system is most easily implemented through computer hardware. The binary digits 0 and 1
correspond to the presence or the absence of a digital signal. The manipulation of binary digits is performed
using a combination of boolean logic gates and circuits. Negative numbers can also be represented in the
Binary Number System.
The numbers are represented by creating a sequence of bits, such as 00000, 010100, 011100 etc. Binary
numerals are often subscripted with 2 in order to indicate the base. For example, (110101)2. Numbers that
have no fractional part are called binary integers.
In the figure above, representation of the binary number (101.01)2 is shown. The most significant bit (MSB)
is the bit in a binary number sequence with the largest value. This is usually the bit farthest to the left. The
MSB represents the highest-order place of the binary integer. On the other hand, the Least Significant Bit
(LSB) is the right-most bit of the number.
The maximum possible sequence of binary numbers that can be created using a sequence of n-bits is 2n .
20
Count of possible binary
No. of Bits
numbers
1 21 = 2
2 22 = 4
3 23 = 8
4 24 = 16
0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
For example, an octal number (532.67)8 can be represented in the decimal number system as
(532.67)8 = 5 x 82 + 3 x 81 + 2 x 80 + 6 x 8-1 + 7 x 8-2
21
Octal numbers find applications where the number of bits in one word is a multiple of 3. They are also used
as shorthand for representing file permissions on UNIX/Linux operating systems and representation of
UTF8 numbers, etc. The advantage of using Octal numbers is that it uses fewer digits than the decimal
number system. It has fewer computations and is less prone to the computational errors.
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
22
Some popular uses of Hexadecimal numbers are:
● Representation of addresses in memory.
● Representation of colors on web pages.
● Representation of Media Access Control (MAC) addresses.
● Display error messages.
23
Ques 1 - Convert decimal number 75 to binary number.
=(1001011)2
= (10001110.1010)2
24
1. Repeatedly multiply the fractional part by 8 and note the integer and fractional part of the product.
2. Repeatedly multiply the fraction part by 8 and note the integer part from top to the bottom. (Stop if
you get 0)
3. Repeat this procedure till sufficient precision is reached (usually 2 to 3 places after the radix point).
= (150)8
= (1063.7070)8
25
3. Repeat this procedure till sufficient precision is reached (usually 2 to 3 places after the radix point).
= (258)16
= (31)16
26
1. Multiply each digit with its respective weighted power of 8.
2. Calculate its sum.
27
Binary Number Hexadecimal Number Binary Number Hexadecimal Number
0000 0 1000 8
0001 1 1001 9
For the integer part, make groups of four bits together starting from the left side of the radix point, and for
the fractional part, make groups of four bits towards the right side of the radix point.
Replace each group with the corresponding hexadecimal number, we get the hexadecimal equivalent of the
given binary number.
NOTE: Add any number of 0’s in the left most bit for integer part, and 0’s in right most bit for fractional
part required to complete the grouping of 4 bits.
Ques 1 - Convert binary number 1000110101110 to hexadecimal number.
Converting Binary Number into Decimal Number:
= (1000110101110)2
= 1 x 212 + 0 x 211 + 0 x 210 + 0 x 29 + 1 x 28 + 1 x 27 + 0 x 26 + 1 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 1 x 21 +
0 x 20
= 4096 + 0 + 0 + 0 + 256 + 128 + 0 + 32 + 0 + 8 + 4 + 2 + 0
= (4526)10
= (11AE)16
28
Ques 2 - Convert Binary number 10010111101101 into Hexadecimal Number.
2 5 E D
= (25ED)16
1 6 4 9 C
Hence the equivalent Hexadecimal Number is (164.9C)16
D 2 . 9 2 A B
29
Binary Number System to Octal Number System
There are two ways to convert a binary number to a hexadecimal number:
1. Convert binary number to decimal number or octal number, and then convert to octal number.
2. Using grouping of bits
Binary Number Octal Number
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
For the integer part, make groups of three bits together starting from the left side of the radix point, and for
the fractional part, make groups of three bits towards the right side of the radix point.
NOTE: Add any number of 0’s in the left most bit for integer part, and 0’s in the right most bit for fractional
part required to complete the grouping of 3 bits.
1 3 3 2
= (1332)8
30
Ques 1 - Convert Octal Number 767 to Binary Equivalent Number.
7 6 7
= (100111001110.001101)2
4 B (11) 2 A (10)
= (45452)8
F E 6
31
1111 1110 0110
= (7746)8
2 1 0 6
= (446)16
Ques 2 - Convert Octal Number 765 into Hexadecimal Number.
7 6 5
=1 1111 0101
= (1F5)16
32
Encoding Schemes
Encoding is defined as the process to convert data from one form to another. Computers only understand
binary language. There is a need to convert popularly used languages by humans into machine
understandable format. Textual characters (letters, numbers and symbols) are assigned unique numerical
codes. Some of the popular encoding schemes are ASCII, ISCII and Unicode.
ASCII
● ASCII stands for American Standard Code for Information Interchange.
● It was developed in the United States of America by American Standards Association (ASA).
● It is used to represent textual information in computers.
● ASCII uses 7-bits for encoding.
● A maximum of 128 characters may be encoded. Out of these 128 characters, only 95 are printable
including the digits 0-9, lowercase and uppercase characters a-z A-Z and punctuation marks. The
rest of the characters are Control Characters.
ISCII
● ISCII stands for Indian Script Code for Information Interchange (ISCII).
● ISCII is an extended version of the ASCII code and uses 8 bits for encoding.
● It was developed by the Bureau of Indian Standards, India.
● It represents various languages from India.
● Some of the supported scripts are Devanagari (Hindi, Marathi, Sanskrit, Konkani), Gujarati,
Kannada, Punjabi, Malayalam, Telugu, Tamil, Oriya, Bengali-Assamese etc.
Unicode
● Unicode Standard is developed and managed by the Unicode Consortium, which is a non-profit
organization composed of members from Software Development companies such as Apple, Adobe,
Google, IBM, Microsoft etc.
● It aims to provide a universal platform for encoding characters of various languages from the world.
● It assigns a unique Code Point to every character, independent of the CPU architecture/platform, or
the underlying software.
● Unicode covers most writing scripts across the world. As of now, over 161 scripts are included in
the latest version of Unicode.
● Unicode defines two mapping methods: the Unicode Transformation Format (UTF) encodings, and
the Universal Coded Character Set (UCS) encodings.
● Various versions of UTF are UTF-8, UTF-16, UTF-32.
● All UTF encodings map code points to a unique sequence of bytes.
33
○ UTF-8 uses 8-bits or 16-bits or 24-bits or 32-bits for each code point.
○ UTF-16 uses 16-bits or 32-bits for each code point.
○ UTF-32 uses 32-bits for each code point.
Q. What is hardware?
A. Hardware are physical components which can be seen and touched (tangible). Examples of hardware
include CPU, mouse, keyboard, monitor, motherboard, cables, CPU case, power supply unit, RAM, graphic
card, sound card etc.
Q. What is software?
A. Software is a set of instructions, its documentation and data, which are stored digitally on the computer.
The software is intangible, i.e cannot be touched. Examples are Microsoft Windows, Linux, Paint, Word,
PowerPoint, Photoshop, VLC Media Player, VS Code, Python.
Q. What is a mouse?
A. The mouse is an input device responsible for the movement of the cursor on the computer’s screen.
Q. What is a keyboard?
A. The keyboard is an input device based on the traditional typewriter, which uses an arrangement of keys.
Keyboards come in various layouts and languages.
Q. What is a scanner?
A. Scanner is an input device that optically scans and digitally captures images from physical photographic
prints, documents, posters etc. Commonly used office scanners use light beams to scan documents placed
on a glass flatbed.
34
A. The memory where the contents get erased as soon as the power is turned off is called volatile memory.
Q. What is a nibble?
A. A sequence of 4-bits is called a nibble.
Q. What is a byte?
A. A sequence of 8 bits is called a Byte (B).
Q. What are the base values of the octal and hexadecimal number system?
A. The Octal number system uses base-8 whereas the Hexadecimal number system uses base-16.
35
A. Data is any sequence of one or more symbols. In other words, raw facts and figures constitute data.
Whereas, Data when processed or interpreted is known as Information.
Q. What is Encoding?
A. Encoding is a system that maps characters, symbols, or textual elements to numeric values or bit patterns
for digital representation and storage. It is used to represent human-readable text and symbols as binary
data, which can be processed, transmitted, and stored in computers and other digital systems.
36
A. ALU is responsible for performing arithmetic operations (addition, subtraction, multiplication, and
division) and logical operations (AND, OR, NOT) on binary data. ALUs are designed to work with binary
numbers, where each bit represents a value of either 0 or 1.
37
Q. What is the purpose of the system bus?
A. The system bus provides a path facilitating the flow of data between the central processing unit (CPU),
memory, and various peripheral devices. The system bus is typically divided into three main types of buses,
Address Bus, Control Bus and the Data Bus.
38
Device Drivers - It is an interface between a particular device and the operating system. It ensures proper
functioning of the device, overall management of a particular device.
Q. What is the reason for grouping the 4 bits in a binary number to form a Hexadecimal number?
A. The hexadecimal number system uses 16 unique symbols (base-16) for representing numbers, and with
4 bits, each digit in the hexadecimal system can be represented uniquely. Therefore, 4-bit binary sequences
are sufficient to represent all possible symbols in the hexadecimal number system.
Q. Which input device is most suitable for the OS with the following user-interface (UI)?
1. Graphical UI
2. Command Line UI
3. Gesture Based Interface
4. Voice Based Interface
5. Touch Based Interface
ANS. 1. Mouse
2. Keyboard
3. Camera/Webcam
4. Microphone
5. Touch-screen
39
A. HDD stands for Hard Disk Drive. It is a mechanical non-volatile secondary storage device. SSD stands
for Solid State Drive, which is a non-volatile memory that stores data without moving parts. SSDs are faster,
more durable, more compact, quieter, and consume less energy.
Q. What is OCR?
A. OCR stands for Optical Character Recognition. It is a pattern recognition technology that identifies the
text present in digital form, such as an image, document etc.
Q. What is MICR?
A. MICR stands for Magnetic Ink Character Reader. It is a device that reads a special kind of ink which is
sensitive to magnetic fields. It is often used to verify the originality of cheques and other documents.
40
Q. Explain different types of OS User Interface.
Q. Explain the difference between primary memory and secondary memory.
Q. What is the need of Cache memory?
Q. How are high level languages converted into low level languages?
Q. Write down some advantages of computers.
Q. Convert the following numbers from one number system to another:
1. (945)10 = (?)2 Ans. (1110110001)2
2. (42)10 = (?)8 Ans. (52)8
3. (194)10 = (?)16 Ans. (C2)16
4. (10110)2 = (?)10 Ans. (22)10
5. (745)8 = (?)10 Ans. (485)10
6. (E1A)16 = (?)10 Ans. (3610)10
7. (0010111)2 = (?)16 Ans. (17)16
8. (6FA2)16 = (?)2 Ans. (0110111110100010)16
9. (101111)2 = (?)8 Ans. (57)8
10. (532)8 = (?)2 Ans. (101011010)2
11. (C45D)16 = (?)8 Ans. (142135)8
12. (165)8 = (?)16 Ans. (75)16
41
12. The cache memory stores the most frequently used data and instructions to improve system
performance.
13. The ROM (Read-Only Memory) is a non-volatile memory that retains its data even when the
power is turned off.
14. The central processing unit (CPU) consists of the control unit and the arithmetic logic unit (ALU).
15. The system bus is responsible for managing communication between the CPU and other
components.
16. The primary purpose of an operating system is to manage computer resources.
17. A group of eight bits is known as a byte.
18. An instruction is a basic arithmetic or logical operation that the CPU can perform.
19. The physical components of a computer system are referred to as hardware.
20. A cache is a small, high-speed memory located close to the CPU that stores frequently accessed
data.
21. A software is a collection of programs and data that enables a computer to perform a specific task.
42
Q. Boolean OR Operator results True if both the inputs are true, otherwise false. (False)
Q. A logic circuit is an electronic circuit used in computers to perform a logical operation using Logic
Gates. (True)
Q. The Control Unit is responsible for Arithmetic and Logical Operations. (False)
Q. System Bus is a pathway for signals to travel from one location to another in the Computer System.
(True)
Q. The CPU directly interacts with the Secondary Memory. (False)
Q. Typically, RAM is faster than Hard Disk Drives. (True)
Q. RAM is larger in size than the Secondary Memory. (False)
Q. Static RAM needs constant refreshing to preserve the data. (False)
Q. RAM is non-volatile in nature. (False)
Q. ROM stores the software that is used to start-up the computer. (True)
Q. BIOS stands for Basic Input Output System. (True)
Q. Cache memory reduces the access time of RAM by storing the frequently accessed items. (True)
Q. The base of binary, octal, decimal and hexadecimal number systems are 2,8,10 and 16 respectively.
(True)
Q. A binary number is made of a sequence of bits. (True)
Q. 1 KiloByte (KB) = 1024 MegaBytes (MB) (False).
Q. Each hexadecimal digit has a unique 4-bit representation. (True)
Q. 1 MegaByte (MB) = 1024 KiloBytes (KB) (True)
Q. Interpreter is a System Utility software. (False)
Q. Compiler is a Language Translator Software. (True)
Q. Microsoft Windows is an example of Application Software. (False)
Q. Device Drivers translate code from high level language to low level language. (False)
Q. Compiler and Interpreter convert high level languages to low level languages. (True)
Q. Command Line User Interface uses Graphical Icons and Menus for navigation. (False)
43
Multiple Choice Questions
(Choose any one out of four choices)
1. Which of the following translators converts high level language into low level language at
once?
a. Assembler
b. Compiler
c. Interpreter
d. None of the above
2. Which of the following is a System Utility?
a. Windows
b. iOS
c. Symbian
d. Anti-Virus
44
c. 1024 KB
d. 1024 B
8. A symbol in the binary number system can assume how many values?
a. 2
b. 7
c. 8
d. 10
45
c. Instruction-Program-Outcome
d. Information-Process-Outcome
19. Whenever the computer is started or a software application is launched, the required
program is loaded into ___________ for processing.
a. ROM
b. CPU
c. RAM
d. CU
46
a. American Standard Coding For Information Interdiscipline
b. American Standard Code For Information Initiative
c. American Standard Code For Information Interchange
d. American Simple Code For Information Interchange
Q.
Assertion (A): Computers perform complex tasks with incredible speed and accuracy.
Reason (R): The smallest unit of memory is called a bit.
Answer: Both A and R are true but R is not the correct explanation for A.
Q.
Assertion (A): File Management is one of the roles performed by the OS of a system.
Reason (R): An Operating System is an interface between the user and the hardware and manages all
the resources of a computer.
Answer: Both A and R are true and R is the correct explanation for A.
Q.
Assertion (A): NAND and NOR are called the Universal Gates.
47
Reason (R): OR operator results True(1) if both the inputs are True(1), otherwise False(0).
Q.
Assertion (A): Each symbol in a hexadecimal number system can be represented by a unique 4-bit
binary number.
Reason (R): The hexadecimal number system has 16 unique symbols.
Answer: Both A and R are true and R is the correct explanation for A.
Q.
Assertion (A): Computers understand our language, and hence there is no need to convert into
machine language.
Reason (R): Encoding is defined as the process to convert data from one form to another.
48
Unit II
Computational Thinking and Programming - I
Developing Algorithm
This stage focuses on creating a logical sequence of instructions, called an Algorithm. The algorithm can
be executed by a computer to generate the desired output. An algorithm has a distinct start and end point,
as well as a defined number of steps. For a given problem, more than one algorithm may be possible and
the most suitable algorithm may be chosen.
49
Step 4 → Repeat from divisor to A-1
4a. divide A by divisor and store the remainder as r
4b. If r is zero, set flag_value to False
4c. Increment divisor by 1
Step 3 → If flag_value is False, A is not prime
Step 4 → Else A is prime
STOP
Coding
Coding is the process of creating computer programs.
Testing
Testing is a process to check if an application is working as expected (and not working abnormally). The
main objective of Testing is to find errors.
Debugging
Debugging is the activity to fix the errors found in the application during the testing phase.
Representation of Algorithms
There are two common methods of representing an algorithm —flowchart and pseudocode.
Flowchart
● A flowchart is a graphical representation of an algorithm.
● A flowchart contains various shapes which are connected by arrows, which shows the flow of
control.
50
Shapes used in Flowchart
Oval Start/Stop
Rectangle Process
Parallelogram Input/Output
Diamond Decision/Condition
Draw a flow-chart to identify whether a number taken as the input from the user is an even number
or an odd number?
Algorithm Flow Chart
START
Step 1 → Take an integer number A as input
Step 2 → Divide A by 2, and store the
remainder as r
Step 3 → If r is zero, Display 'Even'
Step 4 → Else Display 'Odd'
STOP
51
Pseudocode
● Pseudocode is a way of representing an algorithm in readable and easy language.
● Pseudocode is not an actual program. So, it cannot be executed.
● Some of the frequently used keywords while writing pseudocode are INPUT, COMPUTE, PRINT
IF/ELSE, START, STOP
Advantages of Pseudo-Code:
1. Easily convertible to a Programming Language
2. Easy to understand and read
Decomposition
Decomposition is the process of breaking a complex computer problem into smaller parts that are easily
manageable and solvable.
Computer Program:
A computer program is a set of instructions that can be executed by the computer to perform and solve a
certain task. These programs are written in a special language known as Programming Language.
Computer Programming:
It is the process to create a computer program.
Features of Python
● High-level Programming language.
● Interpreted language (as Python programs are executed by an interpreter)
52
● Easy to use
● Simple Syntax
● Python programs are generally written with fewer Lines of Code as compared to other
programming languages.
● Case-sensitive. For example, 'NUMBER' and 'number' are treated differently in Python.
● Portable programming language - has ability run programs on many computer architectures and
operating systems.
Working in Python
● Install Python on the computer (https://www.python.org/downloads/). Refer Appendix for
installation instructions.
● Use Python IDLE (Integrated Development and Learning Environment) for developing python
Programs.
Interactive Mode
In Interactive Mode, a python statement is executed in a command-line shell. It provides instant feedback
for each statement while keeping prior statements in memory.
Script Mode
In script mode, the instructions are saved in a file with a '.py' extension and executed from the beginning of
the file. This mode is suitable for creating and running large programs. In script mode, all commands are
stored in the form of a program or a script.
Character Set:
A character set is a collection of valid characters that can be recognized by a language. Python Language
recognises the following characters as valid:
53
Letters : A-Z, a-z
Digits : 0-9
Special Symbol : + / @ ! - = <> == etc.
Whitespaces : '\n', '\t' etc.
Tokens
Tokens are the smallest individual units of a program.
Keywords
Keywords are reserved words with special meaning (known to the interpreter). These can not be used as
identifiers in a program.
Example: for, while, else, if
Identifier
A variable, function, class, module, or other objects are identified by a name known as identifier.
Rules for naming an identifier:
1. First character of a variable can be an alphabet(A-Z or a-z) or an underscore(_).
2. Next characters of a variable can be an alphabet(A-Z or a-z), an underscore(_) or a digit.
3. Keywords cannot be used as variables.
4. First character cannot be a digit.
5. Special characters including white spaces are not allowed.
Literals:
Literals are data-items that have a fixed value of a certain data type, such as a number, string, boolean, or
None. They are also known as Constants.
Example :
String literals (Text) : 'Hello World'
Numeric literals (Numbers) : 3.14
Boolean literals (Truth Value) : True/False
None Literal : The None keyword is used to define a null value
or absence of a value. None is different from 0.
54
Operators and Operands
Operators are symbols (or keywords) that perform various operations on the operands. An operand is a
variable or a literal on which the operation is performed.
Example: 50 + 20
Here 50 and 20 are operands, and + is the operator.
Arithmetic Operators : Arithmetic operators perform mathematical operations like addition, subtraction,
multiplication, division, floor division, exponent and modulus. (+,-,*,/,//,**,%)
Relational Operators:
Relational operators perform comparison between values. An expression having relational operators
evaluates to either True or False. Example >, <, >=, <=, ==, !=
Python Comments
Comments are descriptions about the code. They help other programmers understand the functionality of
the code. Comments are ignored by the Python interpreter, and are only relevant to the programmer.
Variable
Variables refer to an object (data items like int, float, list, dictionary etc) stored in the memory. Value stored
in a variable can be changed during the program execution.
Rules for naming a variable are the same as the rules for naming an Identifier.
Example: pri = 5
Here pri is a variable with value 5.
55
x = 5+2
In the statement above, the l-value is 'x' as it is on the left-hand side of the = operator.
The r-value is 7 as it is on the right-hand side of the = operator, and is generated by performing the addition
operation on 5 and 2.
The memory location of x may be checked by executing the command id(x).
Python variables are memory references. It may be required to change or update the value of an object
referenced by a variable. However, for certain data objects, Python does not allow us to change the value
of an object.
Mutable Objects:
Mutable data objects are objects that can be changed after they are created. It is possible to add, remove, or
modify elements within these data types. Example of mutable data types: List, Set and Dictionary.
Immutable Objects :
Objects whose values cannot be changed after they are created are called immutable objects. To change the
value, a new object is created. Example of immutable data types: Number (Integer, Float), String, and Tuple.
56
Numeric Data Types (Number)
Python has three numeric data types:
1. Integer
2. Float
3. Complex
Integer
● Numbers with No Fractional Part
● Can be Positive or Negative
● In Python 3, the int type has no max limit. Values can be as large as the available memory allows.
● Example 100, 0o55 (octal number), 0x68(hexadecimal number)
Float
● Numbers with Fractional Part
● Example 3.14, .314E01
Complex
● Numbers with both real and imaginary components
● A complex number is represented by "x + yj". Example 10 + 9j
Boolean
A boolean data type can assume one of the two possible values : True or False.
57
Sequence: Sequence is an ordered collection of items or elements which includes several built-in types
as String, List, and Tuple. Values in the sequence are called elements/items. Each element in a sequence
has a unique index.
String:
● A string is an ordered sequence of characters enclosed in single/double/triple quotes.
● Single Line String : Terminates in a single line. Example – 'This is an example of single line'
● Multi Line String : Does not terminate in a single line. A multiline string may be created using three
quotes
Example -
'''This is a
Multiline
string'''
List:
● List is an ordered sequence data type which can store values of any data type.
● List is mutable.
● List is enclosed in square brackets [ ]
● Example : [ ] is an empty List,
[5, 6.5, True, 'Hello'] is a List having 5, 6.5, True and 'Hello' as four
elements.
Tuple:
● Tuple is an ordered sequence which can store values of any data type.
● They are immutable, i.e the items of a Tuple cannot be updated after creation.
● Tuple is enclosed in parenthesis ( )
● Example : t=( ) is an empty Tuple
t=(9,) is a Tuple with 9 as an item
t=(8, 5, 9.5, False) is a Tuple with 8, 5, 9.5, False as four items
Dictionary:
● Dictionary in Python stores items in the form of key-value pairs
● Syntax is dict_variable = {key1:value1, key2:value2, …, key-n:value-n}
● Items in a dictionary are enclosed in curly brackets { } and are separated by commas
● In a key-value pair, the key is separated from the value using a colon (:)
● To access any value in the dictionary, specify the key as the index using square brackets [ ].
● Example : { } is an empty dictionary,
D = {'name':'Python','version':'3.7.2', 'OS': 'Windows'}
print(D['version']) # shows 3.7.2 as output
58
Special Data-type: None
The None data type/keyword is used to indicate absence of a value (No value or Missing Value).
Expression
An expression is combination of operators, operands, literals and parenthesis. An expression produces a
value when evaluated.
Python Statement
In Python, a statement is an instruction that the interpreter can execute.
Types of Operators
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Identity Operators
6. Membership Operators
Arithmetic operators: Arithmetic operators perform mathematical operations such as addition,
subtraction, multiplication, division, and modulus.
59
Modulo Operator
The modulo operator (%) evaluates the remainder of the operation when the operand on the left is divided
by the operand on the right of the modulo operator.
Example
15 % 7 = 1
13 % 7 = 6
Relational Operators: Relational operators compare the operands. They evaluate to either True or
False.
Logical operators:
Logical operators combine logical values of true or false into a logical expression. They evaluate to either
True or False. There are three basic types of logical operators: 'NOT', 'AND', and 'OR'.
Assignment operators:
Variables are assigned values using assignment operators.
Example :
sum = 5 + x
result += 5
60
Here, the sum variable is assigned the sum of 5 and x. And, the result variable is assigned the sum of
result and 5.
Identity Operators
The identity operators in Python are "IS" and "IS NOT". They check whether the two objects are of the
same data type and share the same memory address.
Example :
x = 5
y = 5
if x is y:
print("x and y are the same object")
else:
print("x and y are different object")
Output will display x and y are the same object because both of them reference the same memory location.
Membership Operators
The membership operators in Python are 'IN' and 'NOT IN'. They check whether the operand on the left
side of the operator is a member of a sequence (such as a list or a string) on the right side of the operator.
Example :
x = ['Red', 2, 'Green']
if 'Red' in x:
print("Found")
else:
print("Not Found")
Output will display Found because the item 'Red' is a member of the List x.
Operator Precedence
Operator precedence determines the priority of operators in an expression. The precedence of various
operators is shown in the Precedence Table.
61
For example, x = 7 + 3 * 2; will result in 13, not 20, because operator * has higher precedence than +. The
expression is evaluated as 7 + 6.
Associativity refers to the order in which operators of the same precedence are evaluated. The associativity
of an operator may be left-to-right or right-to-left.
Precedence Table
Evaluation of Expression
1. Evaluate the expression 50 + 20 * 30
Evaluation:
= 50 + (20 * 30) #precedence of * is more than that of +
= 50 + 600
= 650
2. Evaluate the expression 100 - 20 + 50
Evaluation:
The two operators (–) and (+) have equal precedence and the associativity is from left to right so the left
operator (i.e. -) will be evaluated first.
= (100 – 20) + 50
= 80 + 50
= 130
62
= 9 + 27 * 4 // 3 (* and // has left to right associativity)
= 9 + 108 // 3
= 9 + 36
= 45
Type conversion
It is the process of converting the value from one data type into another. Python supports two ways of Type
conversion:
● Implicit conversion
● Explicit conversion
Implicit conversion
This type of conversion is performed by Python Interpreter automatically without the user's intervention.
Example:
num1 = 20 # num1 is integer
num2 = 30.5 # num2 is float
sum1 = num1 + num2 # sum1 will use float to avoid
# loss of fractional part during addition
print(sum1)
print(type(sum1))
Output:
50.5
<class 'float'>
Explicit Conversion:
This type of conversion is performed by the user manually. It is also known as type-casting. Explicit type-
casting is performed using functions such as int( ), float( ), str( ) etc.
Syntax : new_data_type (expression)
Example
num1 = input("Enter a number : ") # takes a string input by default
var1 = int(num1) #converts string to integer
var1 = var1 * 3
print(var)
Output
Enter a number : 2
6
63
Input and Output in Python
Data Input:
input( ) function is used for getting input from the user. It returns the input as a String data type by default.
Explicit type casting is required to convert the input string into any other data type if required.
Data Output:
print( ) function is used for displaying output on the screen.
Example-1
num1 = int(input("Enter a Number : ")) # type casting the input from
String to Int
print("The Number is : ", num1)
Example-2
num = int(input("Enter a Number : "))
num_cube = num*num*num
print("The cube is : ",num_cube)
Errors
An error is a problem that occurs in a program. Error sometimes halt the program execution, or produce
unexpected results, and cause the program to behave abnormally.
● Syntax error
● Logical error
● Runtime error
Syntax Error
Syntax are the rules for framing statements in a programming language. Any violations in the rules while
writing a program are known as Syntax Errors. They prevent the code from executing and are detected by
the Python interpreter before the execution of the program begins.
Some of the Common Syntax Errors are
64
● Parenthesis Mismatch
● Misspelled keyword
● Incorrect Indentation
Logical Error
Logical errors occur when the code runs without any errors, but the output is not as expected. Logical errors
are caused by a problem in the logic of the code.
Example : Average = mark_1 + mark_2 / 2 # incorrect calculation of average marks
Corrected Code : Average = (mark_1 + mark_2 ) / 2
Runtime Error
A runtime error causes abnormal termination of the program during the execution. Runtime error occurs
when the statement is correct syntactically, but the interpreter cannot execute it.
num1 = 5.0
num2 = int(input("num2 = ")) #if the user inputs zero, a runtime error
will occur
print(num1/num2)
Flow of Control
Flow of Control refers to the order in which statements are executed in a program.
Sequential Flow
The default control flow in a program is sequential flow, in which statements are executed line-by-line one
after the other in a sequence in which they are written.
Example
x = 6
y = 7
z = y - x
print(z)
65
Conditional Flow
Conditional flow refers to execution of certain statements only if a specific condition is met. This is
accomplished by the use of conditional statements such as if, if-else, and if-elif-else.
Example
num = int(input("Enter a number : "))
if(num>5):
print("Number is greater than 5")
else:
print("Number is less than 5")
Output
Enter a number : 55
Number is greater than 5
Iterative Flow
Example-1
name = input("Enter your name : ")
for x in range(5): # range function creates a sequence of integers from 0 to 4
print("Hello", name)
Example-2
name = input("Enter your name : ")
i=1
while i<=5:
print("Hello", name)
i +=1
66
Conditional Statements
Conditional statements execute specific blocks of code based on certain conditions. In Python, conditional
statements are implemented using the keywords if, if-else, and if-elif-else.
Terminology
Indentation
Indentation refers to the spaces at the beginning of a line.
Example
if a<5:
print(a)
print('Inner Block')
print('Outside block')
Block of code
A block of code is a set of statements that are grouped together and executed as a single unit. A block of
code is identified by the indentation of the lines of code.
if statement
The if statement is used to execute a block
of code only if a certain condition is true.
Syntax:
if <condition>:
Set of Statements
Example-
67
Program
Write a python Program to find the absolute value of the number entered by the user.
num = int(input("Enter any number : "))
if num>=0:
abs_num = num
else:
abs_num= -num
print(abs_num)
Output
Enter any number : -5
5
Program
Write a python Program to sort three numbers entered by a user.
a = float(input("Enter the first number : "))
b = float(input("Enter the second number : "))
c = float(input("Enter the third number : "))
if a > b:
a,b = b,a
if a > c:
a,c = c,a
if b > c:
b,c = c,b
print (a, "<", b, "<", c)
Output
Enter the first number : 30
Enter the second number : 25
Enter the third number : 20
20.0 < 25.0 < 30.0
if-else statement
The if-else statement is used to execute one block of code if a certain condition is true, and another block
of code if the condition is false.
68
Syntax of if-else
if <condition>:
set of statements
else:
set of statements
Example
69
Program
Write a python Program to check if a number entered by a user is divisible by 3.
num=int(input("Enter a number : "))
if num % 3 == 0:
print(num,"is divisible by 3")
else:
print(num,"is not divisible by 3")
Output
Enter a number : 601
601 is not divisible by 3
if-elif-else statement
if-elif-else statement is used to check multiple conditions.
Program
70
Iterative Statement
Iterative statements execute a set of instructions multiple times. 'for' and 'while' loops are the iterative
statements in Python.
while Loop
The while loop repeatedly executes a block of code as long as the specified condition is true.
The while loop is an exit controlled loop, i.e. the user is responsible for exiting the loop by changing the
value of the condition to False. While loop may run infinitely if the condition remains true.
Syntax:
while (condition):
block of statements
Example
Write a Python Program (using a while loop) to Find the Sum of First 10 Natural Numbers.
num=1
sum=0
while (num <= 10):
sum = sum + num
num = num+1
print ("Sum of Natural Numbers : ", sum)
Example
Write a Python Program (using the while loop) to Find the Sum of First N Natural Numbers where N is
entered by the user.
num=1
sum=0
n = int(input("Enter the value of n : "))
while (num <= n):
sum = sum + num
num = num+1
print ("Sum of Natural Numbers : ", sum)
71
range( ) Function
range( ) is a built-in function that returns a sequence of numbers.
Syntax
range(start, stop, step)
start: The starting value of the sequence (inclusive). If not specified, it defaults to 0.
stop: The ending value of the sequence (exclusive).
step: The difference between two consecutive elements. Its default value is 1.
The range( ) function can be used in for loops to iterate over a sequence of numbers.
for Loop
The for loop is used to iterate over a sequence (such as a list, tuple, string, etc.) and execute a block of code
for each item in the sequence.
Syntax
for <control_variable> in <sequence>:
Block of code
72
Example-1 Example-2
list1 = [1,2,3,4,5,6,7,8,9,10] str1 = 'India'
for var1 in list1: for each_character in str1:
print(var1) print(each_character)
Program-1
Write a Python Program (using for loop) to Find the Sum of First 10 Natural Numbers.
sum=0
for num in range(1,11):
sum = sum + num
print ("Sum of Natural Numbers : ", sum)
Output:
Sum of Natural Numbers : 55
Program-2
Write a Python Program (using for loop) to Find the Sum of First N Natural Numbers where N is entered by the
user.
sum=0
n = int(input("Enter the value of n : "))
for num in range(1, n+1):
sum = sum + num
print ("Sum of Natural Numbers : ", sum)
Output:
Enter the value of n : 20
Sum of Natural Numbers : 210
Program-3
Write a Python Program (using for loop) to find the factorial of a number.
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
else:
for i in range(1, num + 1):
factorial *= i
print("The factorial of", num, "is", factorial)
Output
Enter a number: 5
The factorial of 5 is 120
73
Break and Continue Statement
Break Statement: The break statement is used to terminate a loop immediately. It is typically used with
conditional statements.
Continue Statement: The continue statement skips all the remaining statements in the current iteration of
the loop and moves the control to the beginning of the next iteration.
Example :
fruits = ['apple', 'banana', 'cherry']
for x in fruits:
if x == 'banana':
break
print(x)
Example :
Write a program in Python to check if a number entered by a user is a prime number or not.
num = int(input("Enter a number: "))
flag=False
if num > 1:
for i in range(2, num):
if (num % i) == 0:
flag=True
break
if flag==True:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
Example :
Write a program in Python to print all natural numbers from 1 to 10 except 7.
for i in range(1,11):
if i==7:
continue
print(i)
Example :
Write a program in Python to print all natural numbers between 1 and 50 (both inclusive) which are not
multiple of 3.
for x in range(1, 51):
if x % 3 ==0 :
continue
print(x)
74
Nested loops
Nested loops refers to a loop within a loop.
Example: Generating a pattern
n = int(input("Enter the number of rows: "))
for i in range(n):
for j in range(i+1):
print("*", end="")
print()
Output
Enter the number of rows: 5
*
**
***
****
*****
String
String: String is a sequence of UNICODE characters. A string can be created by enclosing one or more
characters in single, double or triple quotes (' ' or '' '' or ''' ''').
Example
>>> str1 = 'Python'
>>> str2 = "Python"
>>> str3 = '''Multi Line
String'''
>>> str4 = """Multi Line
String"""
Terminology
Whitespace Characters: Those characters in a string that represent horizontal or vertical space.
Example: space (' '), tab ('\t'), and newline ('\n')
75