Computer Science With Python Class 11
Computer Science With Python Class 11
CLASS - 11
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.
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.
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:
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.
a. (B4)16 = (180)10
b. (84)16 = (132)10
c. (A.5)16 = (10.3125)10
a. (1011001)2= (89)10
b. (1101101)2 = (109)10
c. (100101.111)2 = (37.875)10
a. (11010101100111)2 = (3567)16
b. (0101011110101101)2 = (57AD)16
c. (10101100110011110)2 = (1599E)16
a. (101101010111)2 = (5527)8
b. (111111110111)2 = (7767)8
c. (1110000011111)2 = (16037)8
(ii) X(X+Y) =X
Truth Table for X(X+Y) =X
Ans.
(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
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
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
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 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.
(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
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.
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
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
Ans.
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
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
Step 1: Start
Step 4: if (i>N)
Go to Step 8
Endif
Step 6: i = i + 1
Step 7: Go to step 4
Step 9: Stop
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.
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.
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).
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.
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)
8. Find out the error(s) in the following code segments and rewrite the corrected code.
11. Write a program that accepts the name of a student as input and displays the subject
list to choose from.
Ans.
12. Write a program to accept the name and phone number of a person and display the
following message:
Ans.
Ans.
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'
d. toTAL_1 – Valid
g. \n – Escape Sequence
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
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.
7. What is type conversion? How many types of data type conversions are there in
Python? Explain using example.
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.
Lab Activity
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
a. False
b. 53.0
c. 10
d. 6.0
e. False
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.
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.
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)
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.
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.
Ans.
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)
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”)
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.
8. Write the syntax for a nested block of ‘if-else’ inside another ‘if-else’ block.
Ans. if(expr):
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
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
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.
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
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”)
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")
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)
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() + " "
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
Corrected code:
S="Save Tiger"
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
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)
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])
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)
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")
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
Ch-11 Tuples
4. Which built-in function is used to count the total number of elements of the tuple?
Ans. len()
Syntax: len(tuple)
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.
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.
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)
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)
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)
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!")
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)
14. Find the errors in the code and write the corrected code.
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"}
empDict['emp3']['salary'] = 8500
print(empDict)
dict1={'Ten':10,'Twenty':20,'Thirty':30}
dict2={'Thirty':30,'Forty':40, 'Fifty':50}
d=dict1.copy()
d.update(dict2)
print(d)
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)
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.
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.
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.
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.
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