Class XI Model Paper Sub: Computer science
Q1. Create a List given below and write the most appropriate list method to perform the following
task: lst = [20,30,78,90,50,90] [20]
a) Add an element 90 at the index of 4 in the given list
b) Add element 100 in the last position of the list
c) Delete 2nd element from the given list
d) Add elements 55, 77, 82 at the end of the given list.
e) Count the occurrence of element 90 in the given list.
f) Sort the elements in the list in descending order.
g) Find the max element in the list.
h) Find the sum of the elements of the list.
i) Return the length if the list.
j) Return the index of the element 78 of the given list.
Q2. Write a python program to perform the following tasks on the given string. [20]
string: Str=”Python is a programming Language ”
(i) To print the length of string.
(ii) To print the whole string in upper case.
(iii) To print the string in reverse order
(iv) To print the string in title case
(v) To replace substring ‘Python’ with ‘Hello’ in the string
(vi)To find the index of the substring “ing”.
(vii) Return the substring “Language”
(viii) Remove the leading and trailing whitespaces.
(ix) Splits the string ( separator “programming”)
(x) Return the number of occurrences of substring ‘o’.
Q3. Create a dictionary 'EVEN' of even numbers between 1 and 10, where the key is the decimal number
and the value is the corresponding number in words.
Perform the following operations on this dictionary:
(i) Display the keys
(ii) Display the values
(iii) Display the items
(iv) Find the length of the dictionary
(v) Check if 7 is present or not
(vi) Check if 2 is present or not
(vii) Retrieve the value corresponding to the key 8
(viii) Delete the item from the dictionary corresponding to the key 4
(ix) Add a new key value pair 12: ” Twelve” in the dictionary.
(x) Find the maximum and minimum value of the dictionary.
Q4. Create a Tuple given below and write the most appropriate tuple method to perform the
following task: T1 = (120,230,450,234,112,156) [20]
(i) To display the element with maximum value from the given tuple.
(ii) To display the element with minimum value from the given tuple.
(iii) To display the sum of elements from the given tuple of numbers.
(iv) Arrange the elements in the descending order.
(v) Return the number of elements in the tuple.
(vi) Display the index of the minimum element in the tuple.
(vii) Return the number of occurrences of the element 112.
Answer key
Q1. lst = [20, 30, 78, 90, 50, 90]
# a) Add an element 90 at the index of 4 in the given list
[Link](4, 90)
print(lst)
# b) Add element 100 in the last position of the list
[Link](100)
print(lst)
# c) Delete 2nd element from the given list (index 1)
del lst[1]
print(lst)
# d) Add elements 55, 77, 82 at the end of the given list
[Link]([55, 77, 82])
print(lst)
# e) Count the occurrence of element 90 in the given list
print( [Link](90))
# f) Sort the elements in the list in descending order
[Link](reverse=True)
print(lst)
# g) Find the max element in the list
print( max(lst))
# h) Find the sum of the elements of the list
print(sum(lst))
# i) Return the length of the list
print(len(lst))
# j) Return the index of the element 78 in the given list
print([Link](78))
Q2. Str = "Python is a programming Language "
# (i) To print the length of string
print(len(Str))
# (ii) To print the whole string in upper case
print([Link]())
# (iii) To print the string in reverse order
reverse_string = Str[::-1]
print("String in reverse order:", reverse_string)
# (iv) To print the string in title case
print([Link]())
# (v) To replace substring ‘Python’ with ‘Hello’ in the string
print( [Link]("Python", "Hello"))
# (vi) To find the index of the substring “ing”
print( [Link]("ing"))
# (vii) Return the substring “Language”
print(Str[23:32])
# (viii) Remove the leading and trailing whitespaces
stripped_string = [Link]()
print("String after removing leading and trailing whitespaces:", stripped_string)
# (ix) Split the string (separator “programming”)
split_string = [Link]("programming")
print("String after splitting by 'programming':", split_string)
# (x) Return the number of occurrences of substring ‘o’
count_of_o = [Link]("o")
print("Number of occurrences of 'o':", count_of_o)
Q3. # Creating the dictionary with even numbers between 1 and 10
EVEN = {
2: "Two",
4: "Four",
6: "Six",
8: "Eight",
10: "Ten"
}
# (i) Display the keys
print("Keys:", [Link]())
# (ii) Display the values
print("Values:", [Link]())
# (iii) Display the items
print("Items:", [Link]())
# (iv) Find the length of the dictionary
length = len(EVEN)
print("Length of dictionary:", length)
# (v) Check if 7 is present or not
if 7 in EVEN:
print("7 is present in the dictionary.")
else:
print("7 is not present in the dictionary.")
# (vi) Check if 2 is present or not
if 2 in EVEN:
print("2 is present in the dictionary.")
else:
print("2 is not present in the dictionary.")
# (vii) Retrieve the value corresponding to the key 8
v= [Link](8)
print("Value corresponding to key 8:", v)
# (viii) Delete the item from the dictionary corresponding to the key 4
del EVEN[4]
print("Dictionary after deleting the item with key 4:", EVEN)
# (ix) Add a new key-value pair 12: "Twelve" in the dictionary
EVEN[12] = "Twelve"
print("Dictionary after adding key 12:", EVEN)
# (x) Find the maximum and minimum value of the dictionary
max_value = max([Link]())
min_value = min([Link]())
print("Maximum value in the dictionary:", max_value)
print("Minimum value in the dictionary:", min_value)
Q4. # Given tuple
T1 = (120, 230, 450, 234, 112, 156)
# (i) To display the element with maximum value from the given tuple
max_value = max(T1)
print("Maximum value:", max_value)
# (ii) To display the element with minimum value from the given tuple
min_value = min(T1)
print("Minimum value:", min_value)
# (iii) To display the sum of elements from the given tuple of numbers
Total= sum(T1)
print("Sum of elements:", Total)
# (iv) Arrange the elements in the descending order.
# Since tuples are immutable, we will convert it to a list to sort it.
s= sorted(T1, reverse=True)
print("Elements in descending order:", s)
# (v) Return the number of elements in the tuple
length = len(T1)
print("Number of elements in the tuple:", length)
# (vi) Display the index of the minimum element in the tuple.
min_index = [Link](min_value)
print("Index of the minimum element:", min_index)
# (vii) Return the number of occurrences of the element 112
c= [Link](112)
print("Number of occurrences of 112:", c)