Samplepaper Pt2 Xi Cs 2022-Marking-Scheme
Samplepaper Pt2 Xi Cs 2022-Marking-Scheme
Section A
1. Write output of the following python code 2
(i) LIST = [1123, 2246, 3398, 4412, 5563, 6630, 7758]
print(len(LIST))
Ans : 7
(ii) TUP = ['Harish', 'Manish', 'Suresh', 'Kamal', 'Sohan']
print(TUP[2])
Ans : Suresh
2. What value is stored in the variable ‘var1’ and ‘var2’ in the following python code? 2
var1 = min( [98, 45, 62, 14, 1007] )
var2 = max( (102, 304, 567, 839, 214) )
Ans: 14 839
3. After executing the following code, What you get on screen 2
code=['AB', 'BC', 'CD', 'DE', 'EF', 'GH', 'IJ', 'JK', 'KL', 'LM', 'MN']
print( code[ 3 : 9 ] )
print( code[ -8 : 7 ] )
Ans: ['DE', 'EF', 'GH', 'IJ', 'JK', 'KL']
['DE', 'EF', 'GH', 'IJ']
4. Explain about the following functions in python with example 2
(i) sum() (ii) sort()
Ans: sum() sums up the numbers in the list.
sum([1,2,3,4] gives 10
The sort() method sorts the list ascending by default.
list1 = [11,2,43,4]
list1.sort()
print(list1)
output
[2, 4, 11, 43]
5. Write the values stored in the variable ‘result’, when we import math module 2
(i) result = math.sqrt(81) (ii) result = math.pow(4,3)
Ans : 9.0
64.0
6. What do you mean by mutable and immutable property of data object? Write 2
example of mutable and immutable data object in python.
Ans If the value can change, the object is called mutable, while if the value cannot
change, the object is called immutable. Objects of built-in types like (int, float,
bool, str, tuple, unicode) are immutable. Objects of built-in types like (list, set,
dict) are mutable.
7. Write answers of (i) and (ii) below 2
1
(i) Consider the following list myList. What will be the elements of myList after the
following two operations?
myList = [10,20,30,40]
myList.append([50,60])
myList.append([80,90])
Ans: [10, 20, 30, 40, [50, 60], [80, 90]]
(ii) What will be the output of the following code segment?
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for i in range(0, len(myList)):
if i%2==0:
print(myList[i])
Ans: 1
3
5
7
9
8. Consider the following tuples, tuple1 and tuple2: 2
tuple1 = (24, 2, 46, 68, 46, 10, 56, 46, 46, 46)
tuple2 = (400, 500, 600)
Find the output of the following statements
(i) print(tuple1.index(46))
(ii) print(tuple1.count(46))
(iii) print(tuple1 + tuple2)
(iv) print(len(tuple2))
Ans: (i) 2
(ii) 5
(iii) (24, 2, 46, 68, 46, 10, 56, 46, 46, 46, 400, 500, 600)
(iv) 3
Section B
9. Write a program to read a list of n integers (positive as well as negative). Create 3
two new lists, one having all positive numbers and the other having all negative
numbers from the given list. Print all three list.
Ans: LIST = [-8,12,-56, 78, -34, -78,10, 22, 44]
positive = []
negative = []
for item in LIST:
if item > 0:
positive.append(item)
else:
negative.append(item)
print(LIST)
print(positive)
print(negative)
10. Write a program to search and show the location of element in a list 3
Ans LIST = []
n = int(input('How many data '))
for i in range(n):
item = int(input('Enter number '))
LIST.append(item)
2
found = False
if not found:
print('Search item not found')
11. Write a program to find largest and smallest number in a list. 3
Ans LIST = []
n = int(input('How many data '))
for i in range(n):
item = int(input('Enter number '))
LIST.append(item)
print('Largest is ',largest)
print('Smallest is ',smallest)
12. Write a program to store employee name and salary in a dictionary. 3
Ans n = int(input('Enter number of employees whose data is to be stored '))
employee = dict()
for x in range(n):
name = input('Enter the name of employee ')
salary = int(input('Enter the salary '))
employee[name] = salary
Section C
13. The record of a student (Name, Roll No.,Marks in five subjects and percentage 4
of marks) is stored in the following list:
Write Python statements to retrieve the following information from the list
RecordList.
3
Ans: print(RecordList[3])
print(RecordList[2][4])
print(max(RecordList[2]))
RecordList[0] = 'Ritika'
14. What is the difference between list and tuple in python? What is the role of 4
‘index’ in list and tuple.
List is a mutable data object while tuple is a immutable data object. It means
list can be modified but tuple cannot be changed.
List or tuple Elements Can Be Accessed by Index. Individual elements in a list
can be accessed using an index in square brackets. An index is a number that
defines the position of an element in any given list. Python list works in 0 (zero)
base indexing. First element is at index 0, second at index 1 and so on. If a list
is of size N, the last element is at index N – 1.
15. What is the purpose of mean, median and mode in statistics module of python. 4
Explain with the help of examples.
Mean, Median, and Mode ·
Mean - The average value ·
Median - The mid point value ·
Mode - The most common value.
mport statistics
LIST = [1,3,3,3,5,5,5,5,7,19,20,26]
print(statistics.mean(LIST))
print(statistics.median(LIST))
print(statistics.mode(LIST))
8.5
5.0
5