88% found this document useful (8 votes)
14K views69 pages

Computer Science With Python Class 11

OK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
88% found this document useful (8 votes)
14K views69 pages

Computer Science With Python Class 11

OK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 69

Computer Science with Python

CLASS - 11

Copyright @ Kips Learning Pvt. Ltd 2022.


Kips Computer Science with Python
Book XI
Answer Key

Ch-1 Computer and its Organisation

Section B: Unsolved Questions


A. Short answer type questions.
1. Define data and information.
Ans. Data is a collection of raw or unorganised facts. Information is an organised and
processed form of data.

2. What is processing?
Ans. Processing is the “work” being done, in a program. The transformation of data to get a
known and meaningful result is known as processing.

3. Write any two characteristics of computer.


Ans. Two characteristics of computer are:
Versatility: It refers to the ability to perform a variety of tasks concurrently or sequentially.
Storage: A computer has memory to store data. It can store instructions, processes, results, etc.

4. What are the basic components of a computer?


Ans. There are four basic components of a computer – input unit, CPU, output unit, and
memory/storage unit.

5. What is the role of input and output units?


Ans. Input unit is used for entering data into the computer system through input devices,
like keyboard, mouse, etc.
Output unit is responsible for displaying the information that has been produced by the CPU
after processing the input data.

6. Why do you use a scanner?


Ans. A scanner is used to convert paper-based text or images into a digital form that can be
stored on a disc.

7. What is the CPU?


Ans. CPU stands for Central Processing Unit. It requires memory to store intermediate
results and keep instructions on a temporary basis. It carries out the instructions to perform
arithmetical, logical, and input/output operations.

8. Distinguish between the ALU and CU.


Ans. The Arithmetic Logical Unit (ALU) carries out all the arithmetic and logical operations,
like addition, subtraction, multiplication, division, and comparison.

Copyright @ Kips Learning Pvt. Ltd 2022.


Control Unit is responsible for managing various components of the computer. It controls all
the operations of a computer system like, input, processing, and output.

9. Describe any two output devices.


Ans. Printer: A printer is an output device that prints text or illustrations on a paper. It
generates a hard copy output.
Speakers: Speakers produce audio output that can be heard by the user. The computer’s
sound card generates a signal that is used to produce sound via the computer speakers.

10. Write any one difference between RAM and ROM.


Ans. Random Access Memory (RAM) is a volatile memory, i.e., its contents are erased when
power supply is cut off. Read Only Memory (ROM) is a non-volatile memory, i.e., its
contents are not erased even in the case of a power cut.

11. Describe bit and bytes.


Ans. A bit is the smallest or elementary unit of computer memory. A bit can either store a 0
or 1. A byte is a set of 8 bits. Mostly, the computer memory is represented in terms of bytes.

12. Define Static RAM and Dynamic RAM.


Ans. Static RAM holds data in a static form. However, it can hold data only as long as the
power is supplied to it. Dynamic RAM requires less physical space to store the same amount
of data that is stored using Static RAM.

13. Define EEPROM.


Ans. EEPROM stands for Electrically Erasable and Programmable Read Only Memory. It is
programmed and erased electrically.

14. Write a short note on cache memory.


Ans. Cache memory holds frequently requested data and instructions so that they are
immediately available to the CPU when needed.

15. Why is secondary memory required? Explain.


Ans. Secondary memory is required to store information permanently and for a longer
period. It is a non-volatile storage.

16. What is optical memory? Give any two examples.


Ans. Optical memory uses light beams for its operation. It is mainly used for storing
audio/video and taking backups. Blu-Ray Disc, Compact Disc, and DVD are the examples of
optical memory.

17. How are hardware and software interdependent?


Ans. Hardware and software components are interdependent to each other. Hardware is
required as a physical component that allows activities to be completed, while software is
integrated and installed within the hardware component to assist in its operation.

Copyright @ Kips Learning Pvt. Ltd 2022.


18. What is software? List different types of software.
Ans. Software is a non-tangible component of a computer. It is a set of programs, which is
designed for a well-defined function.

19. Distinguish between a compiler and an interpreter.


Ans. The interpreter only converts one statement of the program at a time into machine
code. Programming languages such as Ruby and Python, for example, use interpreters.
The compiler scans the source code and converts it all at once into machine code.
Programming languages such as C and C++, for example, utilise compilers.

20. Write any two functions of the operating system.


Ans. File Management: Operating system is responsible to manage all file activities like, file
creation, modification, and deletion.
Memory Management: The operating system is responsible to allocate memory to the
different processes and applications. The main task of memory management is to manage
free and occupied memory using different processes.

B. Long answer type questions.


1. List any two input and output devices and explain their functions.
Ans. Input Devices:
Scanner: A scanner is used to convert paper-based text or images into a digital form that can
be stored on a disc.
Mouse: Mouse is a pointing device. It is commonly used as cursor-control device.
Output Devices:
Printer: A printer is an output device that prints text or illustrations on a paper. It generates
a hard copy output.
Speakers: Speakers produce audio output that can be heard by the user. The computer’s
sound card generates a signal that is used to produce sound via the computer speakers.

2. What are the various types of software?


Ans. Computer software can be broadly classified into two categories:
System Software: System software is defined as a set of programs that controls the overall
operations and internal working of a computer system. It functions as a bridge between the
hardware and application software. It controls, integrates, and manages the hardware
components and software of a computer.

Copyright @ Kips Learning Pvt. Ltd 2022.


Application Software: Application software is a set of one or more programs designed to
carry out operations for a specific purpose desired by the end user, like creating and editing
documents, doing calculations, and arranging data in an organised manner. Different
computer languages are used by software developers while developing application
software. Application software cannot run on itself but is dependent on system software to
execute.

3. Explain utility software.


Ans. Utility software assists in the smooth functioning of the computer system and helps it
to perform better. It performs tasks related to managing a computer, its devices, or
programs. Antivirus, compression, disk repair, and network programs are some of the
examples of utility software.

4. Explain the types of language translators.


Ans. Language processor is a special translator program that converts source code into
machine code or object code. There are mainly three types of language processors:
Assembler: It converts low-level assembly code into relocatable machine code, and
generates information for the loader.
Compiler: The compiler scans the source code and converts it all at once into machine code.
Programming languages such as C and C++, for example, utilise compilers.
Interpreter: The interpreter only converts one statement of the program at a time into
machine code. Programming languages such as Ruby and Python, for example, use
interpreters.

5. What are the different types of ROM available?


Ans. Read Only Memory (ROM) is non-volatile memory. The following are different types of
ROM:
PROM: Programmable Read Only Memory
EPROM: Erasable and Programmable Read Only Memory
EEPROM: Electrically Erasable and Programmable Read Only Memory
EAPROM: Electrically Alterable Programmable Read Only Memory

6. What is the difference between system software and application software?


Ans. Application software is a set of one or more programs designed to carry out operations
for a specific purpose desired by the end user. MS PowerPoint and library management
system are some examples of application software.
System software is defined as a set of programs that controls the overall operations and
internal working of a computer. Device drivers and language translators are the examples of
system software.

7. What is the operating system interface? Explain its types.


Ans. Operating system provides a user interface through which users may interact with the
computer system. Different types of user interface are:
• Command Line Interface
• Menu Driven Interface

Copyright @ Kips Learning Pvt. Ltd 2022.


• Graphical User Interface
• Touchscreen Graphical User Interface

8. Explain the various components of the CPU.


Ans. There are three basic components of a CPU:
• Arithmetic Logical Unit: The Arithmetic Logical Unit (ALU) carries out all the
arithmetic and logical operations, like addition, subtraction, multiplication, division
and comparison.
• Control Unit: Control Unit is responsible for managing various components of the
computer. It controls all the operations of a computer system like, input, processing,
and output.
• Memory Unit: The CPU requires memory to store intermediate results and keep
instructions on a temporary basis. It uses main memory to store such information.
9. What are the different functions of the operating system?
Ans. There are four basic functions that an operating system performs:
Process Management: Operating system is responsible to allocate time for the process to be
executed.
Device Management: It specifies the functions of devices on which one or more application
are executed.
File Management: Operating system is responsible to manage all file activities like, file
creation, modification, and deletion.
Memory Management: The operating system is responsible to allocate memory to the
different processes and applications. The main task of memory management is to manage
free and occupied memory using different processes.

10. Explain the role of process management of the operating system.

Ans. Operating system is responsible to allocate time for the process to be executed. The
execution of the process must progress in a sequential order or based on some priority or
algorithms. Process management is the task of an operating system to divide a process into
various states and manage memory, time, and resources according to the status of these
states.

11. What is the difference between hardware and software?


Ans. Hardware: A physical device or component of a computer that is physically attached to
the computer is referred to as hardware. These are the main electronic components that
make up a computer. A computer processor (Central Processing Unit), memory devices
(RAM), monitor, keyboard, mouse, and storage devices are examples of hardware.

Software: A software is a set of programs, which is designed for a well-defined function. A


program is a series of instructions written to solve a particular problem. Software is a non-
tangible component of a computer. It tells a computer 'what to do'.

Copyright @ Kips Learning Pvt. Ltd 2022.


12. What do you understand by the different states of a process?

Ans. The state of a process is defined by the current activity of that process. Each process
may be in one of the following states:

• New: In this state, the process is being created.


• Running: In this state, instructions are being executed.
• Waiting: In this state, the process is waiting for a different event to occur.
• Ready: In this state, the process waits for the processor.
• Terminated: In this state, the process has finished executing.

Ch-2 Number System

Section B: Unsolved Questions


A. Short answer type questions.
1. What is the radix of the following number system?
Ans.
a. Binary = 2
b. Octal = 8
c. Decimal = 10
d. Hexadecimal = 16

2. Write the digits of the hexadecimal number system.


Ans. The digits used to represent numbers in Hexadecimal number system are 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F.

3. What is the purpose of the encoding scheme?


Ans. Computers use encoding techniques to represent and recognise letters, numbers, and
symbols. This method is used to represent characters in binary codes.

4. How are ASCII and ISCII encoding schemes different?


Ans. ASCII is an acronym for the American Standard Code for Information Interchange. It is a
7-bit character encoding scheme in which each bit represents a distinct character.
The ISCII is an acronym for the Indian Script Code for Information Interchange. It is an
encoding scheme for a variety of Indian languages that are written and spoken in India.

5. What is the difference between UTF-8 and UTF-32?


Ans. UTF-8 is a variable length encoding system in which varying numbers of bytes are used
to represent distinct characters, whereas UTF-32 is a fixed length encoding scheme in which
all Unicode code points are represented by exactly 4 bytes.

6. What is the Unicode encoding scheme?


Ans. Unicode is a universal character encoding standard. It assigns a code to every character
and symbol in every language in the world.

Copyright @ Kips Learning Pvt. Ltd 2022.


7. Encode the word ‘INDIA’ using ASCII and convert the encoded value into a binary value.
Ans.
I N D I A
49 4E 44 49 41
01001001 01001110 01000100 01001001 01000001

8. Encode the word ‘DREAM’ using ASCII and convert the encoded value into a binary
value.
Ans.
D R E A M
44 52 45 41 4D
01000100 01010010 01000101 01000001 01001101

9. What is the positional number system and the non-positional number system?
Ans. In a non-positional number system, each symbol represents the same value regardless
of its position. A positional number system is a method of representing numbers using an
ordered set of numerical symbols, in which the value of each digit is determined by its
position.

10. What is radix in a number system?


Ans. The number of independent digits used in the number system is known as Radix or Base of
the number system.

B. Long answer type questions.


1. Represent the following decimal numbers into their binary equivalents:
Ans.
a. (12)10 = (1100)2
b. (205)10 = (11001101)2
c. (45)10 = (101101)2
d. (88)10 = (1011000)2
e. (75.56)10 = (1001011.10001111010111000011)2
f. (22)10 = (10110)2

2. Represent the following decimal numbers into their octal equivalents:


Ans.
a. (102)10 = (146)8
b. (48)10 = (60)8
c. (99)10 = (143)8
d. (198)10 = (306)8
e. (83.25)10 = (123.2)8

Copyright @ Kips Learning Pvt. Ltd 2022.


f. (12.01)10 = (14.00507534121727024366)8

3. Represent the following hexadecimal numbers into their decimal equivalents:

a. (B4)16 = (180)10
b. (84)16 = (132)10
c. (A.5)16 = (10.3125)10

4. Convert the following binary numbers into their decimal equivalents:

a. (1011001)2= (89)10
b. (1101101)2 = (109)10
c. (100101.111)2 = (37.875)10

5. Convert the following octal numbers into their hexadecimal equivalents:

a. (732)8 = (474)10 = (1DA)16


b. (241.32)8 = (161.40625)10 = (A1.68)16
c. (65.57)8 = (53.734375)10 = (35.BC)16

6. Convert the following hexadecimal numbers into their octal equivalents:

a. (BAE)16 = (2990)10 = (5656)8


b. (2A)16 = (42)10 = (52)8
c. (1EC)16 = (492)10 = (754)8

7. Convert the following binary numbers into their hexadecimal equivalents:

a. (11010101100111)2 = (3567)16
b. (0101011110101101)2 = (57AD)16
c. (10101100110011110)2 = (1599E)16

8. Convert the following binary numbers into their octal equivalents:

a. (101101010111)2 = (5527)8
b. (111111110111)2 = (7767)8
c. (1110000011111)2 = (16037)8

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-3 Boolean Algebra

Section B: Unsolved Questions


A. Short answer type questions.
1. What is a truth table and why it is used in Boolean algebra.
Ans. The truth table refers to the functional values of logical expressions that show all
possible input combinations to the gate or circuit, as well as the resultant output based on
the combination of these inputs. When putting values into a truth table, you often write
them as 1 (True) or 0 (False).
2. Prove Absorption Law using a truth table.
Ans.
Absorption law states that (i) X +XY = X
Truth Table for X + XY = X

(ii) X(X+Y) =X
Truth Table for X(X+Y) =X

3. State and prove Idempotent law using a truth table.


Ans.
Idempotent law states that:
(a) X + X = X
(b) X . X = X
(a) To prove this law, we will make the following truth table:
X X+X
0 0+0=0
1 1+1=0 (1 carry)
It is proved from the truth table that X+X = X
(a) To prove this law, we will make the following truth table:
X X.X
0 0.0=0
1 1.1=0
It is proved from the truth table that X.X = X
4. Draw the truth table for 3-variables of XNOR.
Ans. X-NOR 3 variables Q= C, B, A is as follows:

Copyright @ Kips Learning Pvt. Ltd 2022.


5. Draw the truth table for 3-variables of NAND.

Ans.

Copyright @ Kips Learning Pvt. Ltd 2022.


6. Why are the NAND and NOR logical gates called universal gates?
Ans. The NAND and NOR gates are referred to as universal gates because they can be
combined to perform any of the basic functions, resulting in an inverter, an OR gate, or an
AND gate.

7. What is the De Morgan’s theorem? State and prove it algebraically.


Ans.
(i) (X + Y)’= X’.Y’
Now to prove De Morgan’s first theorem, we will use complementation laws. Let us
assume that P = X + Y where, P, X, Y are logical variables.
Then, according to complementation law P + P’ =1 and P . P’= 0
That means, if P, X, Y are Boolean variables, then this complementation law must hold
true for variable P.
In other words, if P i.e., if (X + Y)’= X’.Y’, then (X + Y) + (XY)’must be equal to 1.
(as X + X’= 1)
(X + Y) . (XY)’must be equal to 0.
(as X . X’= 0)
Let us prove the first part, i.e., (X + Y) + (XY)’ = 1
(X + Y) + (XY)’= ((X + Y) +X’).((X + Y) +Y’) (ref. X + YZ = (X + Y)(X + Z))
= (X + X’+ Y).(X + Y +Y’) (ref. X + X’=1)
= (1 + Y).(X + 1) (ref. 1 + X =1)
= 1.1
=1
So, first part is proved.

Now, let us prove the second part i.e.,


(X + Y) . (XY)’= 0
(X + Y) . (XY)’ = (XY)’ . (X + Y) (ref. X(YZ)
= (XY)Z) = (XY)’X + (XY)’Y (ref. X(Y + Z)
= XY + XZ) = X(XY)’ + X’YY’ = 0 .Y + X’. 0 (ref. X . X’=0)
=0+0=0
So, second part is also proved.
Thus: X + Y = X’.Y

(ii) (X.Y)’= X’ + Y’
Again to prove this theorem, we will make use of complementation law i.e.,
X + X’= 1 and X . X’= 0
If XY’s complement is X + Y then it must be true that
(a) XY + (X’+ Y’) = 1 and (b) XY(X’+ Y’) = 0
To prove the first part
L.H.S = XY + (X’+Y’)
= (X’+Y’) + XY (ref. X + Y = Y + X)
= (X’+Y’ + X).(X’+Y’ + Y) (ref. (X + Y)(X + Z)
= X + YZ) = (X + X’+Y’).(X’ + Y +Y’) (ref. X + X’=1)
= (1 +Y’).(X’ + 1) (ref. 1 + X =1)
= 1.1
= 1 = R.H.S
Now, the second part i.e.,
XY.(X + Y) = 0

Copyright @ Kips Learning Pvt. Ltd 2022.


L.H.S = (XY)’.(X’+Y’)
= XYX’ + XYY’ (ref. X(Y + Z)
= XY + XZ
= XX’Y + XYY’
= 0.Y + X.0 (ref. X . X’=0)
= 0 + 0 = 0 = R.H.S.
XY.(X’ + Y’)= 0 and XY + (Xʹ +Y’) = 1
(XY)’= X’ + Y’. Hence proved

8. Identify each of these logic gates by their names and complete their respective truth
tables.
Ans.

a) NAND Gate
A B Output
0 0 1
0 1 1
1 0 1
1 1 0

b) NOR Gate
A B Output
0 0 0
0 1 1
1 0 1
1 1 1

c) AND Gate

A B Output
0 0 0
0 1 0
1 0 0
1 1 1

d) XNOR Gate

A B Output
0 0 1

Copyright @ Kips Learning Pvt. Ltd 2022.


0 1 0
1 0 0
1 1 1

e) OR Gate

A B Output
0 0 0
0 1 1
1 0 1
1 1 1

f) NOT Gate

A Output
0 1
1 0

g) NAND Gate
A B Output
0 0 1
0 1 1
1 0 1
1 1 0

h) NOR Gate
A B Output
0 0 0
0 1 1
1 0 1
1 1 1

9. Derive the Boolean expression for the following logical gate


Ans. Y= ((((A+B).C).D).E)

10. Simplify the expression : X.X+ X.X’


Ans. X.X +X.X’
= X.X+0 (as X.X’=0 Inverse/complement law)

Copyright @ Kips Learning Pvt. Ltd 2022.


= X+0 (as X.X=X Idempotent law)
=X

B. Long answer type questions.


1. What is the equivalent binary expression of F = (X + Y ). ( X + Y’)?

Ans. X.(Y+Y’) (as per Distributive law)

2. Draw the logic circuit for the following Boolean Expression: (X’+Y).Z+W’
Ans.

3. Name the law shown here and verify it using a truth table: A + B . C = (A + B). (A + C)

Ans. The name of the given law is the Distributive law.

This law states that:


a) A + B.C = (A + B).(A + C)
b) A(B + C) = A.B + A.C

Truth Table of first law


a) A + B.C = (A + B).(A + C)

Copyright @ Kips Learning Pvt. Ltd 2022.


b) A(B + C) = A.B + A.C

4. Draw a circuit diagram for the function. F= (P+Q’).(P+R).(Q+R’)

5. Explain the principle of duality by giving an example.

Ans. The principle of duality states that starting with a Boolean relation, another relation can be
derived by
1. Changing each OR sign (+) to an AND sign (.)
2. Changing each AND sign (.) to an OR sign (+).
3. Replacing each 0 by 1 and each 1 by 0.

For example, the dual of (X + Y’) is (X’. Y)

9. State and prove De Morgan’s theorem algebraically.

(iii) (X + Y)’= X’.Y’


Now to prove De Morgan’s first theorem, we will use complementarity laws. Let us
assume that P = x + Y where, P, X, Y are logical variables.

Copyright @ Kips Learning Pvt. Ltd 2022.


Then, according to complementation law P + P’ =1 and P . P’= 0
That means, if P, X, Y are Boolean variables hen this complementarity law must hold for
variables P.
In other words, if P i.e., if (X + Y)’= X’.Y’ then (X + Y) + (XY)’must be equal to 1. (as X + X’=
1) (X + Y) . (XY)’must be equal to 0. (as X . X’= 0)
Let us prove the first part, i.e., X + Y) + (XY)’ = 1
(X + Y) + (XY)’= ((X + Y) +X’).((X + Y) +Y’) (ref. X + YZ = (X + Y)(X + Z))
= (X + X’+ Y).(X + Y +Y’)
= (1 + Y).(X + 1) (ref. X + X’=1)
= 1.1 (ref. 1 + X =1)
=1
So first part is proved.

Now let us prove the second part i.e.,


(X + Y) . (XY)’= 0
(X + Y) . (XY)’ = (XY)’ . (X + Y) (ref. X(YZ)
= (XY)Z) = (XY)’X + (XY)’Y (ref. X(Y + Z)
= XY + XZ) = X(XY)’ + X’YY’ = 0 .Y + X’ . 0 (ref. X . X’=0)
=0+0=0
So, second part is also proved,
Thus: X + Y = X’ . Y

(iv) (X.Y)’= X’ + Y’
Again to prove this theorem, we will make use of complementary law i.e.,
X + X’= 1 and X . X’= 0
If XY’s complement is X + Y then it must be true that
(b) XY + (X’+ Y’) = 1 and (b) XY(X’+ Y’) = 0
To prove the first part
L.H.S = XY + (X’+Y’)
= (X’+Y’) + XY (ref. X + Y = Y + X)
= (X’+Y’ + X).(X’+Y’ + Y) (ref. (X + Y)(X + Z)
= X + YZ) = (X + X’+Y’).(X’ + Y +Y’)
= (1 +Y’).(X’ + 1) (ref. X + X’=1)
= 1.1 (ref. 1 + X =1)
= 1 = R.H.S
Now the second part i.e.,
XY.(X + Y) = 0
L.H.S = (XY)’.(X’+Y’)
= XYX’ + XYY’ (ref. X(Y + Z)
= XY + XZ)
= XX’Y + XYY’
= 0.Y + X.0 (ref. X . X’=0)
= 0 + 0 = 0 = R.H.S.
XY.(X’ + Y’)= 0 and XY + (Xʹ +Y’) = 1
(XY)’= X’ + Y’. Hence proved

10. Write the dual forms of the following:


Ans.
a. A+B . B+C + A+C’
b. X.Y+Z’

Copyright @ Kips Learning Pvt. Ltd 2022.


c. P+Q’+R. P’+Q’
d. X+Y. X’+Y’ . X+Z

11. Draw the Boolean logic ….F = AB.(C+D)

12. Draw the Boolean logic…..Q= (A+B).(C.A)

13. Draw the Boolean logic…..F= AB+BC(B+C)

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-4 Problem Solving

Section B: Unsolved Questions


A. Short answer type questions.
1. What is an algorithm?
Ans. It is a problem-solving strategy that gives you step-by-step instructions for achieving a
desired outcome.

2. What is a pseudocode?
Ans. A pseudocode can be written in text-based instructions and does not require any programming
language syntax. It is used for creating an outline or a rough draft of a program.

3. What is the difference between coding and testing?


Ans. Coding: Coding is also known as programming. It is an art of creating a solution of a
problem in a programming language. There are many programming languages that can be
used depending on the requirements.
Testing: The testing process verifies the expected output (i.e., it is working in the same way as per
the requirement), checks for all the possible inputs, and ensures that it can handle errors. In short, it
verifies the correct behaviour of the program.

4. Explain the need for an algorithm.


Ans. Algorithms are used in almost every aspect of computer science. An algorithm is a set
of instructions that allow a computer to accomplish any activity, such as running a calculator
or solving a complex mathematical problem. It is a fundamental step in programming.

5. Define pattern recognition.


Ans. It focuses on making connections between similar problems and experiences. The main
objective of pattern recognition is to find similarities and differences among objects.

6. Define computational thinking.


Ans. Computational thinking is an approach to solve a problem. It formulates to logically
organise and analyse data using different methodologies and tools. The methods for
creating solutions to the problem are algorithms, flowcharts, and pseudocodes.

B. Long answer type questions.


1. Write an algorithm to find the average age of a group of 10 players.
Ans.
1. Start
2. N = 10 (number of players )
3. a = 1 (player’s count)
4. SUM = 0
5. while (a<=10):
Input AGE
Add AGE to SUM
Add 1 to a

Copyright @ Kips Learning Pvt. Ltd 2022.


6. AVG = SUM/N
7. Print("AVG")
8. Stop

2. Ayaan…….Write an algorithm.
Ans.
1. Start
2. Amount = ((2*50) + (35*1.5 )+ (10*2.5) + (15*1))
3. Print("Total amount is", Amount)
4. If (Amount < 500):
Leftamt = 500 - Amount
else
print (Amount is greater than 500)
5. Print ("Your left amount is", Leftamt)
6. Stop

3. Write an algorithm and pseudocode to find the factorial of N.


Ans. Algorithm to find the factorial of N
Step 1: Start
Step 2: Declare variables n, fact, i
Step 3: Initialise variable fact=1 and i=1
Step 4: Repeat until i < = n
4.1 fact = fact * i
4.2 i = i + 1
Step 6: Print fact
Step 7: Stop

Pseudocode to find the factorial of N

Read number
Fact = 1
i=1
WHILE I <= number
Fact = Fact * i
i=i+1
ENDWHILE
WRITE Fact

4. Draw a flowchart to find the sum of first 100 natural numbers. Also, write the pseudocode for
the same.
Ans.
Pseudocode
BEGIN
N = 1, Sum = 0
WHILE N <= 100
Sum = Sum + N
N=N+1
OUTPUT Sum
WHILEEND

Copyright @ Kips Learning Pvt. Ltd 2022.


Flowchart

5. Draw a flowchart to find largest of three numbers X, Y, and Z.

Ans.

Copyright @ Kips Learning Pvt. Ltd 2022.


14. Draw a flowchart to find prime numbers between 1 to 100.
Ans.

Copyright @ Kips Learning Pvt. Ltd 2022.


15. Draw a flowchart which generates the first 50 items of the Fibonacci Series:

16. Write an algorithm and pseudocode to print the cube of numbers till N, where N is obtained
by the user.
Ans.

Algorithm

Step 1: Start
Step 2 : Input N
Step 2: for i from 1 to N
Calculate cube of number as i * i * i
Print cube of number
Step 3: Stop

Pseudocode

BEGIN
Input N
Loop :for i from 1 to N
Calculate cube of number as i * i * i
Print cube of number
End Loop
END

Copyright @ Kips Learning Pvt. Ltd 2022.


17. Write an algorithm to convert a decimal number, n, to binary format.

Ans.

Step 1: Start
Step 2: Divide the number by 2 through % (modulus operator) and store the remainder in an array.
Step 3: Divide the number by 2 through / (division operator)
Step 4: Repeat Step 2 until number is greater than 0.
Step 5: Stop

18. Design a flowchart to compute the sum of the following series:


1+2+3+4+5+…….+n

Step 1: Start

Step 2: Input value of N

Step 3: i=1, sum=0

Step 4: if (i>N)

Go to Step 8

Endif

Step 5: sum = sum+i

Step 6: i = i + 1

Step 7: Go to step 4

Step 8: Display value of sum

Step 9: Stop

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-5 Programming with Python
Section B: Unsolved Questions
A. Short answer type questions.
1. Who developed Python?
Ans. Python was developed by Guido van Rossum in 1991.

2. Python is a free and open source language. What do you understand by this feature of
Python? Explain.
Ans. Python is a free and open-source language. It is developed under an open-source
licence, which means that you can freely distribute copies of this software, read its code,
make changes, and use it.

3. Describe any two features of Python.


Ans. Python is a dynamically typed language. It means that while programming you do not
need to declare the type of variables before their use.
Python is a platform-independent language. Python programs can run on any platform
without making any change to them.

4. What are the different working modes in Python?


Ans. Interactive mode and Script mode are two modes in Python where you can write
instructions.

5. How are interactive mode and script mode different in Python?

Ans. Interactive mode allows you to write single line of code and run the instruction in the
shell itself. Script mode allows you to write multiple lines of code and run the module.

6. What are the applications of the Python language?


Ans. Python language is used to create programs that control the behaviour of a machine or
to express algorithms precisely. Python has a huge built-in library that supports internet
protocols and offers many choices for web development. It is widely used to compute
scientific and numeric problems as it has a huge library of mathematics and data analysis
packages.

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-6 Python Basics
Section B: Unsolved Questions
A. Short answer type questions.
1. What is the difference between keywords and identifiers?
Ans. Keywords are predefined reserved words, which possess special meaning. An identifier
is a unique name given to a particular variable, function or label of a class in the program.

2. How can you create a single-line string literal in Python?


Ans. A single-line string literal can be created by enclosing the string in single or double
quotation marks.

3. What are literals? How many types of literals are allowed in Python?
Ans. In Python, literals or values represent the data items that have a constant or fixed
value. Literals can be defined as data or value that is given to a variable or constant. There
are many literals available in Python such as, string literals, numeric literals, Boolean literals,
and special literal (None).

4. What are tokens? How many tokens are there in Python?


Ans. In Python, tokens are the smallest elements of a program, which are meaningful to the
compiler. Tokens are formed with a sequence of characters, digits, and special symbols
supported by the ASCII format in the Python language. Each element is called as Lexical unit
or Lexical element or Token. There are following types of tokens available in Python:
Keywords, identifiers, literals/values, operators, and punctuators.

5. What is a variable?
Ans. A variable is the name given to a memory location used by a computer program to
store values. This memory location contains values, like numbers, text, etc.

6. What are delimiters in Python?


Ans. The delimiters in Python are the characters or symbols that separate the values. Space,
tab, character, or sequence of characters will also be included in delimiters list to act as
separator for data items.
7. What are Boolean literals in Python?
Ans. There are only two Boolean literals in Python. They are True and False. In Python, True
represents the value as 1 and False represents the value as 0.
8. What are operators? How many different types of operators are available in Python?
Ans. Operators are special symbols that are used to perform some specific task on the
values or variables.
Types of operators available in Python are: Arithmetic Operators, Relational Operators,
Logical Operators, Assignment Operator, Identity Operators, Membership Operators, and
Bitwise Operators etc.
9. Why is the input() function used?
Ans. The input() function is used to take input from a keyboard or console with a prompt
message. The input is generally provided by the user.

Copyright @ Kips Learning Pvt. Ltd 2022.


10. What is the purpose of the type() function?
Ans. The type() method returns the class type of the argument(object) passed as parameter.
B. Long answer type questions.
1. What are the various ways to declare numeric literals?
Ans. There are three types of numeric literals in Python:
• int: These include whole numbers which do not have a fraction part.
• float: These include real numbers, which have integer and fractional values.
• complex: These include imaginary numbers, which are the roots of negative
numbers.
To declare all these literals, assignment operator is used.
a = 34
pi = 3.14
i = a+3j
2. What are Python literals and variables?
Ans. Literals can be defined as data or value that is given to a variable or constant. In
Python, literals or values represent the data items that have a constant or fixed value.
On the other hand, a variable is the name given to a memory location used by a computer
program to store values. This memory location contains values, like numbers, text, etc.
Declaring a variable means binding it to a data type.
3. Write a program that inputs two value and display the swapped value.
Ans. Program:
p = int( input("Enter value for p: "))
q = int( input("Enter value for q: "))
temp = p
p=q
q = temp
print ("The value of p and q after swapping: ", p,q)

4. What is Lvalue and Rvalue in Python? Explain with a suitable example.


Ans. A Lvalue is also called as locator value that occupies some memory location to store
value. In a statement Lvalue means the value on the left hand side and Rvalue refers to the
value on the right hand side.
Here, x is a variable and value 20 has been assigned to x. Usually, Lvalue contains value or
data from Rvalue.
5. What are comments in Python? How many ways are there to add comments in a Python
program?
Ans. In Python, comments are the text notes added to the program to
provide explanatory information about the program. The interpreter and
compiler will ignore the comments in the program. In Python, there are
two types of comments single-line comment and multiline comment.
Single-line Comment: A comment starts with the # (hash) symbol. You can open the script
mode and then try the below written example to understand the role of comment.
Multiline Comment: You need to apply hash(#) at the beginning of every line of code to
make a multiline Python comment.
6. How to add good comment in Python program to make it more readable and effective?

Copyright @ Kips Learning Pvt. Ltd 2022.


Ans. Comments make the code easy to understand. If your source code is 1000 or more
lines long and you need to find a particular code segment in the program, then it is easy to
find with the help of comments. Comments make the program easy to understand by
another person also.

Lab Activity

6. Evaluate the following statements and write down your observations. One is done for
you.
S. No. Statement Output Reason Corrected Code
a. name*2 Error NameError: name 'name' is not name="Radha"
defined name*2
b. Continue=2 2 No error
print(Continue)
c. continue=2 error Syntax error, as continue is a cont=2
print(continue) keyword print(cont)

d. a=0.067e+2 6.7 float literal


print(a)
e. print('hello'+ helloPython Concatenation using + operator in
'Python') string data type
f. print('hello' * '3') Error TypeError: can't multiply sequence by print('hello' * 3)
non-int of type 'str'
g. chk= true Error NameError: name 'true' is not chk=True
defined.
h. #Hello all - Neither error nor output because it is
a comment
i. st="""I am using I am using Multiline string literal
double quotes double
three quotes three
times to make it times to make
multiline string\ it multi line
Learning Python is stringLearning
so much of fun\ Python is so
Enjoy!""" much of
print(st) funEnjoy!
j. a,b,c=5,5.5,’h’ 5 5.5 h Multiple assignment
print(a,b,c)

Copyright @ Kips Learning Pvt. Ltd 2022.


7. Predict the output of the following:
a. x,y = 3,5 b. a=1
x, y, x = x + 1, y + 2, x + 5 a+ = 3
print(x,y) print(a)
Output 8 7 Output 4
c. name = "Teena" d. a=2
print('Hello' + name) print(a>20)
Output HelloTeena Output False
e. x, y = 8, 10 f. a=0
print('x = ',x,'y = ',y) b = None
x, y = y, x print(a,b)
print('new x = ',x,'new y = ',y)
Output x = 8 y = 10 Output 0 None
new x = 10 new y = 8

8. Find out the error(s) in the following code segments and rewrite the corrected code.

S. No. Code Corrected Code S. No. Code Corrected Code

a. age = 23 age = 23 d. else = 20 e = 20


print age print(age) print(else) print(e)
b. Marks = 100 marks = 100 e. 3=a a=3
print(mark) print(mark) print(a) print(a)
c. a, b = 10, 20 No Error f. @total = 9999 total = 9999
print(a and b) print(@total) print(total)

9. What will be the output of the following?


a. x=y=5 b. x = input("enter your name")
print(x, y) print("How are you?", x)
Output 5 5 Output enter your nameAman
How are you? Aman
c. x, y, z = 2, x + 10, x – 10 d. name="name"
print(x, y, z) print(name.split('a'))
Output Error Output ['n', 'me']

Copyright @ Kips Learning Pvt. Ltd 2022.


10. Find the error in the following code and rewrite the corrected code.

a. a = 'Thankyou! for visiting us! / b. a = input("enter value)


Wishing you safe journey!'
Error No error Error Closing quotation symbol missing
Output Output a = input("enter value")
c. x, y = 34 = 23 d. 89, 98 = a, b
Error Can’t assign to literal Error Can’t assign to literal
Output x, y = 34, 23 Output a,b = 89, 98

11. Write a program that accepts the name of a student as input and displays the subject
list to choose from.

Ans.

name = str(input("Enter your name:"))


sub1="English"
sub2="Hindi"
sub3="Science"
sub4="Math"
print("Name of the student is:", name)
print("Choose from the list of subjects:")
print(sub1)
print(sub2)
print(sub3)
print(sub4)

12. Write a program to accept the name and phone number of a person and display the
following message:

Thankyou ___________(name). We have registered your ____________ phone number.


We will connect with you shortly.

Ans.

name = str(input("Enter your name:"))

ph_no= input("Enter the phone number:")

print("Thankyou", name,". We have registered your phone number", ph_no,". We will


connect with you shortly.")

Copyright @ Kips Learning Pvt. Ltd 2022.


13. Write a program that takes input in true and false for the following statement:

Are you a permanent resident of Delhi?

Ans.

user_input = bool(input("Are you a permanent resident of Delhi? True or false: "))

print(user_input)

14. Assign the strings 'Mohandas', 'Karamchand', and 'Gandhi' to variables first, middle,
and last and display the full name.

Ans.

first = 'Mohandas'

middle = 'Karamchand'

last = 'Gandhi'

print(first+ middle+ last)

15. Which of the following variable names are invalid? Justify.

a. try – Python keywords cannot be used as identifiers.

b. 123-password – An identifier name cannot start with a digit.

c. abc@123 – Python identifier cannot use special symbols

d. toTAL_1 – Valid

16. Write the type of the following tokens:


a. for – Keyword
b. cost – Float
c. True – Boolean
d. = – Operator
e. None – Special Literal

f. ””” – Multiline Comment

g. \n – Escape Sequence

h. # – Single line Comment

Copyright @ Kips Learning Pvt. Ltd 2022.


17. Write the purpose of the following escape sequences. Give examples.

Escape Sequence Meaning of Escape Sequence


\n New line character
\\ Backslash (\)
\' Single Quotes (')
\" Double Quotes (")
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
\f ASCII Formfeed (FF)
\N{name} Character named name in the Unicode
database (Unicode only)

Ch-7 Data Types and Operators

Section B: Unsolved Questions


A. Short answer type questions.
1. What is the difference between division operator and floor division operator?
Ans. Division operator divides first number by second number and returns quotient in float
value.
Floor division operator divides the first number by the second number and returns quotient
after truncating the value after decimal point.

2. What is the difference between assignment operator and equality operator?


Ans. The assignment operator (=) assigns a Rvalue to a variable in Lvalue.
Equality operator (==) compares the Lvalue and Rvalue and returns True if both operands
are equal.

3. What is mapping data type? Explain with an example.


Ans. Mapping data type is useful with a large amount of data. In Python, dictionary is a
mapping data type, where key is mapped to its corresponding value. Telephone directory
and library management system are few examples of mapping data type.

4. Explain the purpose of None data type.


Ans. None is a Python keyword that defines null values or no value.

5. What will be the output of the following code?


Ans. False

6. What will be the output of the following code?


Ans.
a==b

Copyright @ Kips Learning Pvt. Ltd 2022.


True
a is b
False
7. Find the error(s):
Ans.
a. x-=23+(a*2)
NameError: name 'x' is not defined
b. print("Turn number:"+3)
TypeError: can only concatenate str (not "int") to str
c. float("hi")
ValueError: could not convert string to float: 'hi'
d. 1+1=1*1
SyntaxError: cannot assign to operator

8. Write the output of the following statements:


Ans.
a. 2417851639229258349412356
b. 21.666666666666668
c. SyntaxError: invalid syntax
d. True
e. False
f. True
g. look carefully look carefully
h. 91.5 (or Syntax Error due to operator)

9. Find error in the following code.


Ans. print(a*b)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

10. Add parenthesis to the following expressions to make the order of evaluation clear.
Ans.
a. (((a+b)%c)==0) or (((a-b) %c)=0)
b. ((3**2)-(2**2))==(3+(2*3))-2

B. Long answer type questions.


1. What are mutable and immutable data types? Support your answer by giving suitable
examples in Python.
Ans. Mutable means to change or modify. A mutable object can be modified after it is
created. List data type is an example of mutable data types. An immutable object cannot be
modified after it is created in Python. String and integer data types are example of
immutable data type.

Copyright @ Kips Learning Pvt. Ltd 2022.


Mutable Data Type Immutable Data Type
L = [2,3,4,5] x= “Test”
print(L) x[2] = ‘x’
L[1] = 6 print(x)
print(L) Output: TypeError
Output: [2,6,4,5]

2. What are membership operators? How many membership operators are there in
Python?
Ans. Membership operators check whether the element is present in the sequence or not.
There are two types of membership operators in Python, in and not in.

3. What is operator precedence? How will it impact the evaluation of an expression?


Ans. Operator precedence is used in a Python expression to determine the order in which
multiple operators in an expression should be executed.
For example:
2+4*3
In this expression high precedence operator get executed (*) first and then (+) operator.
The output will be 14.

4. What is operator associativity? Give example.


Ans. Operator Associativity is used to evaluate the expression if an expression contains two
or more operators with the same precedence.
For example:
40/5*3
In above expression, both the / and * operator has same precedence hence, the expression
will be executed from left to right.

5. What are operators? How many operators are there in Python?


Ans. Operators are special symbols that are used to perform some specific tasks on values
or variables. Majorly there are two types of operators Unary and Binary. Furthermore,
binary operators can be categorised into arithmetic operators, augmented operators,
relational operators, logical operators, identity operators, membership operators and
bitwise operators.

6. What are sequence data types? Explain with an example.


Ans. A sequence is an ordered collection of similar or different data elements, having same
or different data types. In Python, there are three types of sequence data types. They are:
string, list, and tuple.
For example:
S=“hello”
Here, S is a string data type that holds a sequence of characters.

7. What is type conversion? How many types of data type conversions are there in
Python? Explain using example.

Copyright @ Kips Learning Pvt. Ltd 2022.


Ans. The process of converting the value of one data type (integer, string, float, etc.) to
another is called type conversion. Python supports two types of data type conversions:
• Implicit type conversion: Python automatically converts one data type to another.
Example: a=6.7
Here, “a” becomes a variable of float data type automatically when the value 6.7 is
assigned to it.
• Explicit type conversion: Python functions like int(), float(), str() are used to convert
the data type of an object to the required data type.
Example:
a=5
x=float(a)
here, a is int data type and in second statement variable a has been converted to
float data type explicitly.

8. What are identity operators? How they are different from assignment operators?
Ans. The identity operators are used to identify whether an operand or identifier refers to a
certain class, type, or memory. There are two types of identity operators, is and is not.
Identity operators return Boolean value if the operands are identical. On the other hand, the
assignment operator assigns the Rvalue to Lvalue.

9. What is augmented assignment operator? Explain with examples.


Ans. Augmented assignment operator performs the arithmetic operations and assignment
operations simultaneously. These operators are also called compound assignment
operators.
Example: a+=5, here += is an augmented assignment operator which can be read as:
a= a+ 5

10. What is an expression? How are expressions evaluated in Python?


Ans. An expression is a combination of operators, literals, and variables. Python interpreter
evaluates the expression and displays the result.
In an expression, the operators of higher precedence are executed first. Once those results
are obtained, operators of the next precedence are executed.

Lab Activity

15. Write the expressions for the following in Python:

SNo Answer
a. (x**y)**z
b. x=(a**2) – (b**2)
y= (a+b)*(a-b)
x==y
c. A = 3.14 *r*r

Copyright @ Kips Learning Pvt. Ltd 2022.


d. A = 1/3*3.14*r*r*h
e. x=c*c
y=( a**2)+(b**2)
x==y
f. area= side*side
g. A= l*b
h. x = ((1/2)*(a**2 + b**2)+ (1/2)(a**3 + b**3))
i. A = 2*3.14*r

16. Write the expressions for the following:


a. age > 18
b. name == Rakshit and age == 20
c. a = b = 80.5
d. y = 50 + (-10)
y>x
e. x*5 != y*10
f. 17%5
g. 78/3
h. (2.2+1.0+4.5+3.5+2.0) / 5
i.
x,y
float(x)
float(y)
c = (x+y)/2
j. st = ‘990000111’
int(st)

17. Write and evaluate the following expressions in Python:

a. False
b. 53.0
c. 10
d. 6.0
e. False

18. What will be the output of the following expressions?

Expression Output Data Type of Output


35/5 7.0 float
35.5//2 17.0 float
100%2.5 0.0 float
int(8.2+5.34) 13 int

Copyright @ Kips Learning Pvt. Ltd 2022.


True and False False bool
34<35 True bool
34<35 or 35>34 True bool

19. Write a program to take first name and last name from the user and display “Good
morning” with his or her full name.
Ans.
fname = input("Enter first name: ")
lname = input("Enter last name: ")
print("Good morning! " + fname +" " + lname)

20. Write a program to input radius of the circle and calculate its circumference.
Ans.
radius = float(input("Enter the radius of a circle: "))
c = 2*3.14*radius
print("circumference = ", c)

21. Write a program that repeats “All the Best” string 5 times.

Ans.

str = "All the Best"


print(str*5)

22. Write a program to obtain your name, class, and roll number and display the following
message: “Congratulations! You won the Badge of Programming Star”

Ans.

name= input("Enter your name:")


cls=input("Enter your class:")
rno=input("Enter your rno:")
print("Congratulations! You won the Badge of Programming Star")

23. Write a program to input length and breadth of a rectangle and display its area and
perimeter.

Ans.
l = float(input("Enter length of rectangle:"))
b = float(input("Enter breadth of rectangle:"))
area = l*b
p = 2*(l+b)
print("Area of rectangle is:", area)
print("Perimeter of rectangle is:", p)

Copyright @ Kips Learning Pvt. Ltd 2022.


24. Write a program to input an integer and display its square and cube.

Ans.

a = int(input("Enter a number:"))
sq = a*a
cube = a*a*a
print(" Square is :", sq, "Cube is ", cube)

25. Write a program to input a number and print its preceding and succeeding number.

Ans.

a = int(input("Enter a number"))
p=a-1
s=a+1
print("preceding value is: ", p)
print("succeeding value is: ", s)

26. Write a script to input cost price and selling price of an item and display profit or loss.

Ans.

cp=float(input("Enter Cost Price:"))


sp=float(input("Enter Selling Price:"))
p = sp-cp
print("Profit or loss is : ", p)

27. Write a program that calculates simple interest where principal, rate of interest and
time can be obtained from the user.

Ans.
p= float(input("Enter principal amount:"))
roi=float(input("Enter rate of interest:"))
t=float(input("Enter time:"))
si= (p*roi*t)/100
print("Simple interest is: ", si)

28. Write a program to input radius and calculate the area of a circle.

Ans.

radius = float(input("Enter radius of a circle: "))


a= 3.14*radius*radius
print("area = ", a)

Copyright @ Kips Learning Pvt. Ltd 2022.


29. Write a program to carry out average of five numbers. Input the numbers in integer
and float formats.

Ans.

a = int(input("Enter first number:"))


b = int(input("Enter second number:"))
c = int(input("Enter third number:"))
d = int(input("Enter fourth number:"))
e = int(input("Enter fifth number:"))
avg = (a+b+c+d+e)/5
print("Average is: ", avg)

30. Write a program to calculate E in E=mc2.

Ans.
m = float(input("Enter the value of m:"))
c=float(input("Enter the value of c:"))
e= m*(c*c)
print("The value of e is: ", e)

Ch-8 Control Flow Statements

Section B: Unsolved Questions


A. Short answer type questions.
1. What is the difference between break and continue statements?
Ans. The break statement terminates the loop and transfers the control out of the loop.
The continue statement is used to skip the current iteration and transfers the control to the
beginning of the loop.

2. What is the purpose of the empty statement? How you can write an empty statement
in Python?
Ans. The keyword ‘pass’ is used to declare an empty statement. It allows you to create
loops, functions, etc., and you can define the body of the loop or function later. However,
you cannot leave the body of the function or loop empty. In such cases, the pass statement
is useful which does nothing but makes the code syntactically correct. For example:
str = “Test”
for i in str:
pass
print(“Test cleared”)

Copyright @ Kips Learning Pvt. Ltd 2022.


3. What is an infinite loop? Explain with the help of an example.
Ans. If the test expression in the while or for loop will never become false, the loop keeps
on repeating the block of statements infinitely. This state of the loop is called an infinite
loop. For example:
x=1
while ( x==1):
print(“loop”)

4. What are the jump statements in Python? How many types of jump statements are
there?
Ans. Jump statement allows you to change the flow of the loop. There are three types of
jump statements: break, continue, and pass.

5. Why is the while loop called an entry-controlled loop? Justify your answer by giving a
suitable example.
Ans. The while loop is called entry-controlled loop because it first evaluates the test
expression and then executes the body of the loop. If the test expression returns false, then
the control flow will directly go to the else block or come out from the loop.
For example:
n=5
while(n > 1):
print(“inside loop”)
n = n-1
print(“outside loop”)

Here, it checks the condition first and then will execute the statements inside the block.

6. Write the difference between the ‘else’ and ‘elif’ statements.


Ans. The ‘else’ statement is used with an ‘if’ statement. The expression given in the ‘if’
statement is checked. If it returns true, then the statement block following the ‘if’ statement
will be executed, other the statement block after ‘else’ gets executed. On the other hand,
the ‘elif’ statement is used when multiple conditions are to be checked. In the if-elif-else
structure, only the condition that returns true will be executed.

7. What are nested loops?


Ans. A loop inside another loop is called a nested loop. Nested loops are commonly used to
print patterns, series, and mathematical matrix operations.
For example:
for i in range (1,4):
for j in range(1,i):
print('*',end='')
print("")

8. Write the syntax for a nested block of ‘if-else’ inside another ‘if-else’ block.
Ans. if(expr):

Copyright @ Kips Learning Pvt. Ltd 2022.


Statement
if(expr):
Statement
else:
Statement
else:
Statement

B. Long answer type questions.


1. Write a program to print the following pattern.
Ans.
rows = 5
for i in range(rows + 1, 0, -1):
for j in range(0, i - 1):
print("*", end=' ')
print(" ")

2. Write a program to find the numbers which are divisible by 7 and are multiples of 5,
between 1 to 1000 (both included).
Ans.
start_num = int(1)
end_num = int(100)
cnt = start_num
while cnt <= end_num:
if cnt % 7 == 0 and cnt % 5 == 0:
print(cnt, " is divisible by 7 and 5.")
cnt += 1

3. Write a program to print the following series till n terms: 1+2+3+4+…+n


Ans.
s=0
n = int(input("Enter a number: "))
for i in range (1, n+1):
s=s+i
print(s)

4. Write a program to print the following pattern.


Ans.
n=4
for i in range(n):
for j in range(i+1):
print(chr(j + 65), end="")
print()

Copyright @ Kips Learning Pvt. Ltd 2022.


5. Write a program to display the sum of even numbers up to n terms.
2+4+6+8+...+n
Ans.
n=int(input("Enter a number: "))
s=0
for i in range (0, n+1, 2):
s=s+i
print("Sum of even series is: ", s)

6. Write a program that obtains the sum of the squares of whole numbers till the nth
term. [12+22+32+42+…+n2]
Ans Program
n=int(input("Enter a number: "))
s=0
for i in range (1, n+1):
x=i*i
s=s+x
print("Sum of series is: ", s)

7. Write a program to get a string as input from the user and print it in the reverse order.

Ans.
st1 = input("Enter a string : ")

st2 = ''
for i in st1:
st2 = i + st2

print("\nOriginal = ", st1)


print("Reversed = ", st2)

8. Write a program that accepts the gender,……


Ans.
g = input("Enter gender (M/F): ")
ex = float(input("Enter the total number of years of experience: "))
sal = float(input("Enter your salary: "))
if(g=='M'):
if(ex>=10):
sal = (sal + (sal*15/100))
print("salary is: ", sal)
else:
sal = (sal + (sal*5/100))
print("salary is: ", sal)
if(g=='F'):
if(ex>=10):
sal = (sal + (sal*16/100))
print("salary is: ", sal)

Copyright @ Kips Learning Pvt. Ltd 2022.


else:
sal = (sal + (sal*6/100))
print("salary is: ", sal)

9. Write a program to determine whether a given number is a perfect number.


Ans.
Number = int(input("Enter any number: "))
Sum = 0
for i in range(1, Number):
if(Number % i == 0):
Sum = Sum + i
if (Sum == Number):
print(" %d is a perfect number" %Number)
else:
print(" %d is not a perfect number" %Number)

10. Write a program to input a number and check if the number is a prime number or
composite number.
Ans.
Number = int(input("Enter any number: "))
count = 0
for i in range(2, (Number//2 + 1)):
if(Number % i == 0):
count = count + 1
break
if (count == 0 and Number != 1):
print("%d is a prime number" %Number)
else:
print("%d is a composite number" %Number)

Lab Activity
1. What will be the output of the following code:
a. 3
b. 2 to 100 even numbers like 2 4 6 8 10……100
c. 2, 1, 0, -1, -2, -3, -4,
d. True

2. Find the error(s) in the following code and rewrite the corrected code.

SNo Error(s) Corrected Code


A else cannot contain Given in book
condition
B True is a keyword that if True:
starts with a capital print('yes')
letter.

Copyright @ Kips Learning Pvt. Ltd 2022.


C Two else cannot be there if(a+b)>c:
continuously in one print(“sum is big”)
program elif (a+b)<c:
print(“c is big”)
else:
print(“They are equal”)
D Indentation is not proper for i in range(1,2):
for j in range(1,2):
print(i)
E Cannot start with elif, n=2
should start with if if(n>=2):
print(“Yes”)
else:
print(“No”)

3. Predict the output of the following code segments.


a. -10
-15

b.
6
6
6
6
6
7
7
7
7
8
8
8
9
9
10
c. 20
d.
I
I
IL
I Lo
I Lov
I Love
I Love
I Love I
I Love IN
I Love IND
I Love INDI

Copyright @ Kips Learning Pvt. Ltd 2022.


I Love INDIA

4. Find the errors in the following code segments and underline each correction done in the
code:
a.
x= int(input("Enter value of x: "))
for y in range(0,5):
if x==i:
print("present")
else:
print("absent")
b.
a=5
if x>2 or a<5:
print(“Best”)
else:
print(“Thankyou”)

c.
cost =250
i=0
while cost <= 2000:
if (cost <=750):
print(cost)
cost += 250
else:
print(“cost”, i)
i=i+1
cost = cost +250
d.
a=5
while( a<= 10):
print(a)
a=a+1
e.
for x in range(0,5):
if(x==3):
break
else:
print(x)
continue
f.
for x in range(1,5):
pass
print(“over”)

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-9 String Manipulation

Section B: Unsolved Questions


A. Short answer type questions.
1. What is string slicing?
Ans. Slicing in Python means fetching a substring from a string.

2. What is the purpose of the membership operators in Python?


Ans. Membership operators are used to test the presence of an element in a string.

3. What is the purpose of lstrip() and rstrip() functions in Python string?


Ans. The lstrip() function trims the specified characters from the beginning of the string.
The rstrip() function trims the specified characters from the end of the string.

4. Compare the split() and partition() functions.


Ans. The split() function breaks up a given string at the specified separator and returns a list
of substrings.
The partition() method breaks the string from a given parameter. It splits the string from the
first occurrence of the parameter and returns a tuple.

5. What are the different operations that can be performed on strings?


Ans. The operations like concatenation, repetition, and slicing can be performed on strings.
Also, the presence of a character in a string can be checked.

6. Explain the advantages of index() function.


Ans. The index() method returns the index of the first character of the substring in a string,
if found. It gives an error, if the substring is not found.

7. What is the difference between len() and index() functions?


Ans. The len() function is used to find the length of a given string.
The index() method returns the index of the first character of the substring in the string, if
found. It gives an error, if the substring is not found.

8. Explain the concatenation operation with the help of an example.


Ans. String concatenation refers to joining two strings or joining the characters of both the
strings one after another. The ‘+’ operator is used for concatenation operation in Python.
For example:
x = “Dream”
y= “ Big”
print(x + y)
Output : DreamBig

Copyright @ Kips Learning Pvt. Ltd 2022.


9. Define indexing. Explain by giving an example.
Ans. Elements of the string data type can be accessed by using index values. The process of
storing and retrieving elements of an ordered data type using index or key values is called as
indexing. Index values are numeric, either positive or negative.

10. What do you mean by traversing a string? Give an example.


Ans. Traversing means visiting the characters of a strings at least once. The traversal starts
at beginning till end.
Example:
s= “ Train”
i =0
while i < len(s):
c= s[i]
print(c)
i=i+1

B. Long answer type questions.


1. Write a program to ask the users for their full name. It should give the following output:
a. The whole name b. The first character
c. The first five characters d. The fourth, fifth, and sixth characters
Ans.
name=input("Enter your full name:")
print("Whole name is: ", name)
print("First character of name is: " , name[0])
print("First five characters of name is: " , name[0:5])
print("Fourth, fifth, and sixth characters of name are: ", name[3], name[4], name[5])

2. Write a program that asks for a name. It should give the following output:
a. It returns the name in lowercase b. It returns the name in uppercase
c. It returns the name with the first letter as uppercase and the rest in lowercase
Ans.
name= input("Enter your name: ")
print(name.lower())
print(name.upper())
print(name.capitalize())

3. Write a program that asks for a username of six characters in length. It should check the
length of the input string and tell the user whether they have entered six characters or
not.
Ans.
username=input("Enter username of six characters long:")
if(len(username)==6):
print("Your username is six character long and acceptable")
else:
print("Your username is NOT six character long and is unacceptable")

Copyright @ Kips Learning Pvt. Ltd 2022.


4. Write a program that asks for a string. Convert the input string to a secret code by
substituting some of the characters with special characters.
Ans.
st1= input("Enter a string: ")
mystr =st1.lower()
ss= mystr.replace('s','$')
a= ss.replace('1','2')
b= a.replace('2','4')
c= b.replace('3','6')
d= c.replace('4','8')
e= d.replace('5','10')
A=e.replace('a','e')
B=A.replace('e','i')
C= B.replace('i','o')
D= C.replace('o','u')
st= D.capitalize()
print(st)

5. Obtain a string from the user and return the total number of whitespaces that she
enters in between the words of the string.
Ans.
str=input("Enter the string: \n")
spaces=0
for i in range(0, len(str)):
if(str[i]==' '):
spaces=spaces+1
print("The number of spaces are: ", spaces)

6. Write a program to swap commas by dots in a string.


Ans.
st= input("Enter a string with commas: ")
print(st.replace(',', '.'))

7. Write a program to check whether a string contains any special character.


Ans
txt="Python, is a high^^ level language."
x=txt.find('^', 0, 30)
print(x)

8. Write a python program to capitalise the first and last characters of each word in a
string.
Ans.
str1 = input("Enter a string: ")
str1 = result = str1.title()
result = ""
for word in str1.split():
result += word[:-1] + word[-1].upper() + " "

Copyright @ Kips Learning Pvt. Ltd 2022.


r= result[:-1]
print(r)

9. Write a program to print all the words in a given string.


Ans.
s = "I love my India"
s = s.split(' ')
for word in s:
print(word)

10. Write a program to obtain a string including digits and calculate the sum of digits
present in the string.
Ans.
str1 = input("Enter a string: ")
sum_digit = 0
for x in str1:
if x.isdigit() == True:
z = int(x)
sum_digit = sum_digit + z
print(sum_digit)

Lab Activity
5. What will be the output of the following statements?
a. He's a
b. a chip off the old blo
c. ip off the o
d. block

6. What will be the output of the following code segments?


a. qwe
b. MyMyMyBook7
c.
S
Sa
Sav
Save
Save
Save E
Save Ea
Save Ear
Save Eart
Save Earth
d. Hy

7. Find the error and rewrite the corrected code.

Copyright @ Kips Learning Pvt. Ltd 2022.


S="Save tiger"
S[5]='T'
TypeError: 'str' object does not support item assignment

Corrected code:
S="Save Tiger"

8. Find the error and rewrite the corrected code.


a.
print(S1[9])
IndexError: string index out of range
Corrected Code:
print(S1[8])

b.

txt = "Welcome"
x=txt.index('k')
print(x)
ValueError: substring not found
Corrected Code:
x=txt.index('Wel')
print(x)
c.
print('Ganga')*2
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
Corrected code:
print('Ganga'*2)
9. Predict the output of the following:
a. ('', 'a', 'bcABC')
b. True
c. 19

Ch-10 List Manipulation


Section B: Unsolved Questions
A. Short answer type questions.
1. What is the list data type in Python?
Ans. A Python list data type is a collection of data elements of the same or different data
types.

2. Explain any three features of list data type.


Ans. Lists are ordered: A list is an ordered collection of objects.
Lists are mutable: It means that the elements of the list can be changed even after the list is
defined.
Lists are dynamic: Lists are easy to store and handle different operations with ease.

Copyright @ Kips Learning Pvt. Ltd 2022.


3. What is indexing in list data type?
Ans. The elements of a list are indexed in a specific order, with 0 as the first index.

4. What is the difference between append() and extend() functions?


Ans. The function append() adds its arguments as a single element at the end of the list.
The extend() function iterates over its arguments and adds each element to the list at the
end.

5. If you want to add all the numbers present in the list, then which function will you use?
Also, write the syntax of that function.
Ans. The sum() function adds the elements of the sequence and returns the sum.
For example:
num = [2, 2.5, 3]
s = sum(num)
print(s)

6. What is the difference between list and string data types?


Ans. A list is an ordered sequence of object types, and a string is an ordered sequence of
characters.

7. What is slicing in lists?


Ans. Slicing means dividing the list into various sub-lists. The colon (:) operator is used to
access the part of list.
For example:
L=[1,2,3,4]
print(L[0:2])

8. What is the difference between the sort() and sorted() function?


Ans. The sort() function arranges the elements of a given list either in an ascending or
descending order. It changes the list and does not return any value.
The sorted() function arranges the elements of a given list either in an ascending or
descending order. It returns the sorted list.

9. What is the difference between pop() and remove() functions?


Ans. The pop() function removes the element at the given index from the list and returns
the removed item.
The remove() method removes the first matching element that has been provided as the
function argument from the list.

10. What is the purpose of the insert() function in Python list?


Ans. The built-in function insert() allows you to add an element at the specified position in
the list.

11. What is the purpose of the list() function in Python?


Ans. The list() function is also called a constructor. It is used to create a list with values and
also create an empty list.

Copyright @ Kips Learning Pvt. Ltd 2022.


12. How can you compare two lists?
Ans. List can be compared using sort () and sorted() functions.

13. What is the meaning of traversing a list? Explain by giving a suitable example.
Ans. Traversing a list means to visit every element of the list.
Example:
sub=[‘Hindi’, ’Eng’, ’CS’, ’Maths’]
for i in range(len(sub)):
print(sub[i])

14. What is the purpose of the function reverse()?


Ans. The function reverse() is used to reverse the elements of the list. This function does not
return any value.

B. Long answer type questions.


1. Write a program that reverses the list without using a built-in function.
Ans.
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
L = len(numbers)
for i in range(int(L/2)):
n = numbers[i]
numbers[i] = numbers[L-i-1]
numbers[L-i-1] = n
print(numbers)

2. Write a program that takes elements from a user in two lists and creates a third list that
contains all of the elements from the first and second lists.
Ans.
l1 = input("Enter first list: ")
l2 = input("Enter second list: ")
l3 = l1 + l2
print("Joined List:", l3)

3. Write a program that enters a list and moves all the duplicate values at the end of the
list.
Ans.
mylist=[1,2,3,5,6,5,8,3,9,2,1]
for a in range(0, len(mylist)):
for b in range(a-1, -1, -1):
if mylist[a]==mylist[b]:
mylist.append(mylist[b])
mylist.pop(b)
print(mylist)

Copyright @ Kips Learning Pvt. Ltd 2022.


4. Write a program to find the minimum and maximum value of the items present in the
list.
Ans
a_list = [5, 2, 7, 6, 3, 1, 9]
maximum = max(a_list)
print("maximum is: ", maximum)
minimum = min(a_list)
print("minimum is: ", minimum)

5. Write a program that creates a list of characters and numbers and adds a sublist( list
inside a list) with index 3 element.
Ans
l1=[2,5,3,[1,'x',4],'a','e']
print(l1)

6. Write a program that takes the names of the planets and saves them as a 2D list(nested
list). Now, display the names of the planets with 6 or less than 6 characters.
Ans.
planet = [['Mercury'], ['Venus'], ['Earth'], ['Mars'], ['Jupiter'], ['Saturn'], ['Uranus'], ['Neptune']]
few_planet = []
for sublist in planet:
for val in sublist:
if(len(val)<=6):
few_planet.append(val)
print(few_planet)

7. Write a program that creates an empty list and assign float, string, and integer values to
it.
Ans.
l1=[]
l2=['a','b',1,2,3.5]
l3=l1+l2
print(l3)

8. Write a python program that inputs list items and checks whether a particular item is
present in the list or not. Also display the index value of the item if present in the list.
Ans.
test_list = [1, 6, 3, 5, 3, 4]
print("Checking if element 4 exists in the list (using loop) : ")
for i in test_list:
if(i == 4):
x=test_list.index(i)
print ("Element exists at", x+1, "position")

9. Write a program that adds all the list items.


Ans.
total = 0

Copyright @ Kips Learning Pvt. Ltd 2022.


list1 = [10, 5, 15, 18, 20]
for ele in range(0, len(list1)):
total = total + list1[ele]
print("Sum of all elements in given list: ", total)

10. Write a program to find the frequency of an item that is present in the list.
Ans.
marks=[90, 90.5, 90, 95, 90]
c=marks.count(90)
print("number 90 is present :", c , " times in the list")

Lab Activity

10. Predict the output of the following:


a. Python
b. 5
c. [30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
d. ['a’,’b', 'c', 'd', 'e', 'f', 'g']
e. [4, 20, 24, 28]
f. [25, 10]

11. Predict the output of the following:


e. ['ab', [1, 2, 3]]
f. 4
g. [1, 2, 3, 3, 2, 1]
h. [1, 2, 3, 2, 1]
i. 2
j. DAY
k. False
l. [1, 3, 3, 8, 9, 20, 56]
m. expression cannot contain assignment,
n. fruits
cold drink
6.5
8

12. Underline the errors and rewrite the corrected code:


a. vehicles.insert('scooter',3)
TypeError: 'str' object cannot be interpreted as an integer
Corrected code:
vehicles.insert(3,'scooter')
b. i.remove(7)
ValueError: list.remove(x): x not in list
i.remove(3.1)

Copyright @ Kips Learning Pvt. Ltd 2022.


c. li=[['a','b','c',[1,2,3],'p']
missing list bracket
li=[['a','b','c',[1,2,3],'p']]
d. print(c.upper())
AttributeError: 'list' object has no attribute 'upper'
print(c )

Ch-11 Tuples

Section B: Unsolved Questions


A. Short answer type questions.
1. The following code gives output 2. Why?
t=('a', ('b', 'a'), 'a',)
print(t.count('a'))
Ans. The count() function counts the frequency of an element in a tuple. It cannot read the
elements in the nested tuple. To count in nested tuple, count() function can be iterated.

2. Create tuple with a single element.


Ans. To create a tuple with a single element, we need to put a comma after the single
element. For example: t=(8,)

3. Create a tuple that contains the names of 5 states of India.


Ans. states = ('Haryana', 'Rajasthan', 'Karnataka', 'Uttar Pradesh', 'Uttrakhand')
print(states)

4. Which built-in function is used to count the total number of elements of the tuple?
Ans. len()
Syntax: len(tuple)

5. Is d=(3) and d=(3,) same? Justify your answer.


Ans. d=(3) is of int data type and d=(3,) is of tuple data type.
To declare a tuple with the single element, a comma (,) is used after the element to make
the object a tuple data type.

6. What is the difference between the ‘in’ operator and index() function?
Ans. The index() functions returns the index of the first occurrence of a given element in a
tuple. If the element is not present in the tuple, then it will give an error.
The ‘in’ operator is a membership operator. It will check whether the value exists in the
tuple or not. If found, then it returns True, otherwise it returns False.

Copyright @ Kips Learning Pvt. Ltd 2022.


7. Create an empty tuple.
Ans. t=()

8. What is the purpose of the tuple() function in Python?


Ans. The function tuple() is also called constructor. The tuple() function is used to create an
empty tuple as well as tuple with values.

9. What are the characteristics of a tuple?


Ans The characteristics of a tuple are :
• Ordered
• Immutable
• Allows duplicate values
• Allows different data type values

10. How is a tuple different from list data type?


Ans. The list and tuple are different in the following ways:
List Tuple

It is mutable. It is immutable.

Operations like insert and delete can Operations like insert and delete
be performed on list data type. cannot be performed on tuple data
type.
Items of a list can be changed once Items of a list cannot be changed once
assigned. assigned.

11. What is the purpose of the sorted() function?


Ans. The sorted() function sorts the elements of a tuple. The sorting is done in an ascending
order by default. It returns a new sorted list and does not modify the original tuple.

12. Explain the functions max(), min(), and sum() in tuple.


Ans. The max() function returns the highest value item from tuple.
The min() function returns the minimum value item from tuple.
The sum() function returns the total of all the items in a tuple.

13. What is packing and unpacking in Tuple? Explain with an example.


Ans. Packing and unpacking is used to modify the elements of tuple. To create a tuple from
a set of values is called packing and separating individual values from a tuple is called
unpacking.
Example of unpacking and packing:
T1 = (1,2,3,4) #Packing
a,b,c,d =T1 #Unpacking
print(a,b,c,d)
print(T1)

Copyright @ Kips Learning Pvt. Ltd 2022.


14. What will be the output of the following code:
Ans.
(4, 5, 9, 4, 5, 9)
(5, 9, 8, 7, 0, 0)

B. Long answer type questions.


1. Write a program that prints the maximum value in a tuple. Obtain the elements of a
tuple from the user.
tup=eval(input("Enter a tuple:"))
m=max(tup)
print("The element with highest value in tuple: ", m)

2. Write a program that finds the sum of all the numbers in a tuple using while loop.
Ans.
tuple=(1, 12, 32, 2)
s=0
i=0
while(i<len(tuple)):
s=s+tuple[i]
i+=1
print("sum of tuple elements is: ",s)

3. Create a tuple of 10 different items and display them in reverse order.


Ans.
t=(1, 2, 'xyz', 23.4, 77, 10, 'abc', 80, '20', 10)
print("The original tuple is: ", t)
t = t[::-1]
print("The reversed tuple is: ", t)

4. Create a tuple t=(10,20,40,50,60). Add number 30 at index 2.


Ans.
t=(10,20,40,50,60)
temp=list(t)
temp[2]=30
t=tuple(temp)
print(t)

5. Write a program that obtains two tuples, one for marks and another for roll number.
Concatenate both tuples to form a third tuple.
Ans.
marks = (20, 25, 18, 22, 23)
rno = (1, 2, 3, 4, 5)
t = marks+rno
print(t)

Copyright @ Kips Learning Pvt. Ltd 2022.


6. Write a program to create two tuples where you store decimal numbers in one tuple
and integer values in another tuple. Now, create a third tuple to combine both the tuples
and display it.
Ans.
num1=(20, 25, 18, 22, 23)
num2=(1.5, 2.5, 3.5, 4.5, 5.5)
t=num1+num2
print(t)

7. Write a program that inputs marks of five students in their two subjects using nested
tuple and add these numbers to generate total marks for each student.
Ans.
total = ()
for i in range(5):
print("Enter marks of student no.", i+1 )
mark = ()
mark1 = int(input("Enter the marks of first subject = "))
mark2 = int(input("Enter the marks of second subject = "))
print()
mark = (mark1 , mark2)
total= total + (mark,)
print("Final Tuple= ",total)

8. Write a program to create a tuple (2, 3, 4, 5, 6, 7, 8, 9). Now, remove an element at


index 3 and display the updated tuple.
Ans.
t = (2,3,4,5,6,7,8,9)
temp = list(t)
temp.pop(3)
t = tuple(temp)
print(t)

9. Create a tuple ‘single’ with one element and check its type.
Ans
t=(9,)
print(type(t))

10. Create a number guessing game using built-in functions. Input a tuple and the number
to be searched. If the number is present in the tuple, then display “Hurray! You Win”,
Otherwise print, “Try Again!”.
Ans.
tup=eval(input("Enter numbers"))
num=int(input("Enter a number to be searched in a tuple"))
if num in tup:
print("Hurray! You Win")
else:
print("Try Again!")

Copyright @ Kips Learning Pvt. Ltd 2022.


11. Write a program to create a tuple with the cost of products that you have purchased.
Now, find the maximum and minimum amount that you spent. Also, calculate the total
money spent by you for the purchase.
Ans
pur=(100, 200, 160, 178, 267, 34, 378, 289)
m=max(pur)
mi=min(pur)
s=sum(pur)
print("maximum purchase:", m, "minimum purchase: ", mi, "sum is :", s)

12. Write a program that takes the heights of different users and save them in a tuple.
Sort that tuple in an order from shorter height to longer height.
Ans.
h=eval(input("Enter height of 5 users in centimeter"))
sh=sorted(h)
print(sh)

13. Siya is filling the marks list for 8 students, but she made an incorrect entry at index 6.
Write a program to solve her problem by updating that value.
Ans.
t = (63, 53, 60, 50, 60, 45, 55)
temp = list(t)
temp[5] = 30
t = tuple(temp)
print(t)

14. Take your marks for all the subjects in various tests out of 10. Store them in a nested
tuple and find out average of your marks scored in each test.

a = ((1,2),(3,4.15,5.15),(7,8,12,15))
sum = 0
avg= 0
me= 0
for i in range (len(a)):
sum = 0
for j in range (len(a[i])):
sum = sum+a[i][j]
avg= sum/(j + 1)
print ("Average of ", i + 1, "subject :", avg)
me += avg
print ("Average of all: ", me/3)

Copyright @ Kips Learning Pvt. Ltd 2022.


Lab Activity

13. Predict the output of the following code snippets:


a. 1
0
b. (4, 3, 2, 1)
(4, 3, 2)
c. (10, 11, 20, 25, 30)
(30, 25, 20, 11, 10)
d. (9, 10, 1)
(6, 2)
(6,)
e. ('b', 'c')
('b', 'c', 1)
f. (2, 89, 1, 4, 5, 6)

14. Find the errors in the code and write the corrected code.

SNo Error Corrected Code


a -done in book- -done in book-
b IndexError: tuple index out tup=(3.5,6,'a',10)
of range print(tup)
c TypeError: 'tuple' object tup=('cat','dog','mouse')
does not support item print(tup)
assignment
d can only concatenate tuple t1=('India','Australia')
(not "str") to tuple t2=('Sri Lanka',')
t1+t2
e 'type' object does not tup=(5,('a'))*2
support item assignment print(tup)

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-12 Dictionary

Section B: Unsolved Questions


A. Short answer type questions.
1. Explain the purpose of the del keyword with a suitable example.
Ans. The keyword del is used to delete the key that is present in the dictionary. If the key to
be deleted is not found, then it raises an error.
For example:
num = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5}
print("The original dictionary", num)
del num['c']
print("The dictionary after deleting", num)

2. Explain the following dictionary functions:


Ans.
a. get(): If a key exists in the dictionary, then get() function returns the specific value,
otherwise it returns None.
b. pop(): The pop() function can be used to delete a key and its value that has been passed
as the function argument.
c. popitem(): The popitem() function removes and returns the last added key-value pair in
the dictionary.
d. update(): It updates the dictionary with the elements from another dictionary or from
another sequence of key-value pair.
e. fromkeys(): The fromkeys() function creates a new dictionary from the given sequence. It
returns a new dictionary with the values.

3. Write a program to check whether a dictionary is empty or not.


Ans.
d={}
if d.key():
print(“dictionary is not empty”)
print(d)
else:
print(“it is empty”)
print(d)

4. Write a program to find the two highest values in a dictionary.


Ans.
marks = {"Abhay":15, "Khushi":10, "Atharva":16, "Ritu":20}
list1 = sorted(marks.values())
h1 = list1[-1]
h2 = list1[-2]
print("Highest element found = ", h1)
print("Second highest element found = ", h2)

Copyright @ Kips Learning Pvt. Ltd 2022.


5. How can you insert values into a dictionary?
Ans. The elements can be added to the dictionary by adding one value at a time or by using
dict() function.
Example using dict() function:
marks = {}
marks = dict(1:99, 2:80, 3:98, 4: 99.5, 5:95)
print(marks)
Example of adding values one by one:
marks = {}
marks[1] = 99
marks[2] = 80
marks[3] = 98
marks[4] = 99.5
marks[5] = 95
print(marks)

6. Write a Python program to create a dictionary with key values and copy this dictionary
into another dictionary.
Ans.
Under30 = {'Anay': 18,'Ganesha':12,'Ramik':25}
group1=Under30.copy()
print(group1)
7. Identify the error:
Ans. TypeError: unhashable type: 'list'
Corrected code is:
names={("Jan","Feb"):"Month", ("Winter","Summer"):"Season"}

8. Write a program to create a dictionary from a string.


Ans.
string = "{'A':1, 'B':2, 'C':3}"
d = eval(string)
print(d)

B. Long answer type questions.


1. Rename the key ‘city’ to ‘location’ in the following dictionary:
Ans
Dict={"name":"keya","age":25,"salary":8000,"city":"India"}
Dict['location'] = Dict.pop('city')
print(Dict)

2. Change Sandeep’s salary to 8500 in the given dictionary:


Ans.
empDict = {

Copyright @ Kips Learning Pvt. Ltd 2022.


'emp1': {'name': 'Javed', 'salary': 7500},
'emp2': {'name': 'Ruby', 'salary': 8000},
'emp3': {'name': 'Sandeep', 'salary': 6500}
}

empDict['emp3']['salary'] = 8500
print(empDict)

3. Identify and write the function name.


Ans.
a. dict()
b. len()
c. items()
d. pop()
e. clear()

4. Merge the following dictionaries into one:


Ans.

dict1={'Ten':10,'Twenty':20,'Thirty':30}
dict2={'Thirty':30,'Forty':40, 'Fifty':50}
d=dict1.copy()
d.update(dict2)
print(d)

5. Create a dictionary and perform the following operations:


Ans.
employee={'name':'Reema', 'age':30, 'salary':55000}
print(employee)
employee['city']='Mumbai'
print(employee)
employee['salary']=60000
print(employee)
emp=employee.pop('age')
print(employee)
employee.clear()
print(employee)

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-13 Introduction to Python Modules

Section B: Unsolved Questions


A. Short answer type questions.
1. What is Python module?
Ans. The Python module refers to a Python file that contains statements and definitions or
functions.

2. Name the Python library module, which needs to be imported to invoke the following
functions:
Ans.
a. import math
b. import random
c. import math
d. import statistic

3. What will be the minimum and maximum value that can be generated by the following
Python code?
Ans.
Minimum value = 100
Maximum value = 150

4. Write a program to calculate the area of a circle using pi constant from the math
module.
Ans.
import math
r=float(input("Enter radius: "))
a= math.pi*r*r
print("area of circle is: ", a)

Ch-14 Society, Law, and Ethics-I

Section B: Unsolved Questions


A. Short answer type questions.
1. Define digital footprint.
Ans. A digital footprint is a record of the online activity, including posts, queries,
photographs, emojis, likes, and the deleted posts.

2. What are netiquettes?


Ans. Netiquette is a combination of two words, “Net” + “Etiquette”. It refers to the polite
and respectful behaviour while using the internet.

Copyright @ Kips Learning Pvt. Ltd 2022.


3. Write a short note on the responsibilities of a digital citizen.
Ans. The digital citizens also refer to as ‘Netizens’, who have the knowledge and skills to
effectively communicate with others through digital technology. They are the part of digital
society, adhering to the best practices and displaying decorum when it comes to the
internet, communication, and social media.

4. What is the difference between copyright and patent?


Ans.
Copyright is a legal right granted by the law to the creator for his original work.
Patent is a right, relating to the new inventions that grants the inventor the sole right to
make, use, and sell that invention for a specific period.

5. What is IPR and its different types.


Ans. The term IPR refers to Intellectual Property Rights. It exists to safeguard human’s
intellectual accomplishments. IPR provides a framework and policy for protecting creative
works. The different types of IPR are:
• Copyright
• Industrial Design
• Layout Design
• Trade Secret
• Trademark
• Patent

6. What is IPR Infringement?


Ans. IPR infringement refers to the infringement of protected intellectual property rights.
There are three types of IPR violations:
• Plagiarism
• Trademark Infringement
• Copyright Infringement

7. What is ransomware?
Ans. Ransomware is a type of extortion virus that locks your computer and refuses to let
you access information unless you pay a ransom. It is a huge hazard to both individuals and
businesses. Ransomware encompasses virus and Trojan attacks that can wipe out files and
the entire system.

8. What are Open-Source Software?


Ans. Open Source software encourages collaboration and sharing because it allows others
to make changes to source code, update the source code, and redistribute copies.

9. Write a short note on Identity theft.


Ans. When someone steals your personal information, such as your login credentials or
bank account number, they are committing identity theft. Some common examples are,
fraudulent change in address, misuse of credit/debit card numbers, etc.

Copyright @ Kips Learning Pvt. Ltd 2022.


10. What is cybercrime?
Ans. Cybercrime involves the use of an electronic device as well as a network or the
internet.

B. Long answer type questions.


1. Explain cyberbullying by giving an example.
Ans. Cyberbullying is the act of sending messages to others that are intended to anger or
hurt them. Sending unpleasant texts or instant messages, sharing embarrassing images or
videos on social media, and spreading malicious rumours online or via cell phones are the
examples of cyberbullying.

2. What is phishing? How is phishing different from fraud emails?


Ans. Phishing is the practice of obtaining sensitive information about a victim using forged
emails. A hacker sends an email that appears to come from a reputable source and instructs
the receiver to download an attachment or click a link. It is done by delivering a message
that appears to be legitimate and trustworthy (email, SMS, social media, etc.) but actually
contains a link to a forged website.

3. What is eavesdropping? What are the different types of eavesdropping?


Ans. Eavesdropping, also known as a sniffer or snooping attack, happens when an electronic
device steals information being carried over a network. There are two types of
eavesdropping attacks:
Active attack: an attacker tries to modify the content of the messages.
Passive attack: an attacker observes the messages, copies it, and may use it for malicious
purpose.

4. Explain plagiarism. How can you protect yourself from plagiarism?


Ans. Plagiarism is an act of presenting another’s work or ideas as your own. Plagiarism is an
offence and sometimes its consequences may lead to criminal charges. To avoid plagiarism,
follow the certain steps:
a. Always give credit or quote the source or person if you use their work.
b. Paraphrase or cite other’s speech, written or spoken words, etc., in your written or verbal
work.
c. If you include any image, poem or any published material, then cite the origin of work or
media.

5. What is licenced software? Explain by giving suitable examples.


Ans. Licenced software is available with a fee or cost or licence to use it. It is also known as
proprietary software. All the paid software are called licenced software.

Copyright @ Kips Learning Pvt. Ltd 2022.


Ch-15 Society, Law, and Ethics-II

Section B: Unsolved Questions


A. Short answer type questions.
1. Write the full form of
Ans.
a. VIRUS: Vital Resources Under Seize
b. ICT : Information and Communication Technology
c. EEE : Electrical and Electronic Equipment

2. What is the difference between Trojan horse, virus, and worms.


Ans.
Virus Worm Trojan Horse

A virus is a piece of software or Worms proliferate Trojan Horse captures


a computer program that themselves, causing the vital information
connects to another piece of computer system to slow about a computer
software or a computer down. system or network.
program in order to cause harm
to the computer system.

The virus reproduces itself. Worms are also capable of The Trojan Horse, on
self-replication. the other hand, does
not reproduce itself.

Virus can’t be controlled Worms can also be Like virus and worms,
remotely. controlled remotely. Trojan horse can also
be controlled
remotely.

The main objective of virus is to Worms' primary goal is to The main objective of
modify the information. consume system resources. Trojan horse is to steal
the information.

3. What is antivirus software? Give examples.


Ans. An antivirus's primary function is to scan, detect, prevent, and eliminate any existential
threats to the computer system. Norton, McAfee, and Kapersky are three examples.

4. Why was the Information Technology Act 2000 enacted?


Ans. The major goal of this Act is to carry out legal and reliable electronic, digital, and online
transactions, as well as to limit or reduce cybercrime.

Copyright @ Kips Learning Pvt. Ltd 2022.


5. How can you ensure that a website address is secure?
Ans. Check for ‘https’ at the beginning of the URL or the lock icon in the web address bar to
see if a site is safe. If these security signs are not there, then do not share personal and
sensitive information on the website.

6. What is the importance of installing antivirus software on a computer?


Ans. You should install and update the antivirus program on your computer on a regular
basis so that it can detect and remove latest viruses from the system.

7. What do you mean by an identity theft?


Ans. Identity theft occurs when someone steals your personal information such as login
credentials, bank account number, to commit fraud.

8. What do you know about the contribution of project Greene of the government of India
in handling e-waste?
Ans. This project is a part of the Government of India’s ‘Digital India’ programme, which
aims to raise awareness about e-waste and aids in the implementation of e-waste
management.

9. How can you report cybercrime in India?


Ans. The Indian government launched the cybercrime.gov.in service to make it easier for
victims and complainants to lodge cybercrime concerns online. Women and children can
report cybercrime or contact their local police.

10. What types of challenges are faced by people with impairments while using
computers? Which tools are used to assist them?
Ans. ICT aids impaired people by allowing them to learn. ICT assists teachers of pupils with
specific needs in promoting their abilities. For example, the ICT tool immersive reader
assists people in reading text, while tools and ease of access settings enable people to view
large mouse pointers of various colours and adjust settings accordingly.

B. Long answer type questions.

6. How will you report cybercrime in India?


Ans. The Indian government launched the cybercrime.gov.in service to make it easier for
victims and complainants to lodge cybercrime concerns online. Women and children can
report cybercrime or contact their local police.

7. Write a short note on E-waste Management.


Ans. Electronic waste, often known as e-waste, refers to all discarded electrical and
electronic equipment (EEE) and its parts that cannot be reused. E-waste management
process has been deployed to deal with e-waste. It involves the disposal and recycling of
various types of e-waste such that it does not pose any health risks to people and saves the
environment while also producing useful products from trash.

Copyright @ Kips Learning Pvt. Ltd 2022.


8. Write a short note on gender and disability issues faced while teaching and using
computers.
Ans. ICT aids impaired people by allowing them to learn. ICT assists teachers of pupils with
specific needs in promoting their abilities. ICT can empower both teachers and students. ICT
helps teachers to integrate their lesson and create equal opportinuties for girls and boys to
access resources, a common platform to collaborate and share their work.

9. Why is it important to dispose electronic gadgets effectively?


Ans. The discarded electronic and electrical equipment may pose a serious health hazard for
people. The environment may also be harmed by environmental degradation which is
caused by the release of pollutants, gases and particulate matter into the air. Its disposal
has become a global environmental and public health concerns.
E-waste management process has been deployed to deal with e-waste. It involves the
disposal and recycling of various types of e-waste such that it does not pose any health risks
to people and saves the environment while also producing useful products from trash.

10. What are the different ways to keep your data confidential?
Ans. Confidentiality means privacy that prevents unauthorised disclosure of information.
The confidentiality of information can be ensured in the following ways:
• Encryption
• Access Control
• Authentication
• Authorisation
• Physical Security

Copyright @ Kips Learning Pvt. Ltd 2022.

You might also like