Professional Documents
Culture Documents
XII - CS Term 1
XII - CS Term 1
XII - CS Term 1
SONEPAT
Half Yearly Examination [2021-2022]
CLASS – XII
SUBJECT – COMPUTER SCIENCE
Time: 1:30 Minutes M.M. 35
General Instructions:
(i) All questions are compulsory.
(ii) Each question carries 1 mark.
1 Which of the following python scripts will give the given output?
Output: 3 3 3.0
a) x = str(3.0)
y = int(3.0)
z = float(3)
print(x,y,z)
b) x = float(3)
y = int(3)
z = str(3)
print(x,y,z)
c) x = float(3)
y = int(3.0)
z = str(3)
print(x,y,z)
d) x = str(3)
y = int(3)
z = float(3)
print(x,y,z)
2 Which of the following python scripts will give the given output?
apple
banana
cherry
a) fruits = ["apple", "banana", "cherry"]
y, x, z = fruits
print(x)
print(y)
print(z)
b) fruits = ["apple", "cherry", "banana"]
x, y, z = fruits
print(x)
print(y)
print(z)
Page 1 of 17
c) fruits = ["apple", "banana", "cherry"]
z, x, y = fruits
print(x)
print(y)
print(z)
d) fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
3 Select the correct output for given python scripts-
x = "Python is "
y = "awesome"
z= x+y
print(z)
x=5
y = 10
print(x + y)
a) 15
Python is awesome
b) Python is awesome
510
c) awesome is Python
15
d) Python is awesome
15
4 Rupesh has written a python scripts based on list and after execution its showing following output
apple 5 False
cherry 5 True
banana 1 False
Select the scripts which he has written to obtain above results.
a) list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
print(list1[0],list2[2],list3[1])
print(list1[1],list2[0],list3[2])
print(list1[1],list2[0],list3[1])
b) list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
print(list1[0],list2[1],list3[2])
print(list1[2],list2[1],list3[0])
print(list1[1],list2[0],list3[2])
c) list1 = ["apple", "cherry", "banana"]
list2 = [1, 3, 9, 7, 5]
list3 = [True, False, False]
print(list1[0],list2[1],list3[2])
print(list1[2],list2[1],list3[0])
print(list1[1],list2[0],list3[2])
d) list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
Page 2 of 17
list3 = [True, False, False]
print(list1[1],list2[0],list3[1])
print(list1[2],list2[1],list3[0])
print(list1[1],list2[2],list3[0])
5 thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"]
thislist[1:3] = ["blackcurrant", "watermelon"]
print(thislist)
Select the output of given program snippents.
a) ['apple', 'blackcurrant', 'watermelon', 'orange', 'kiwi', 'mango']
b) ["apple", "banana", "cherry", "orange", "kiwi", "mango"]
c) ['apple', 'blackcurrant', ' cherry ', 'orange', 'kiwi', 'mango']
d) ['apple', 'blackcurrant', ' cherry ', ' watermelon ', 'kiwi', 'mango']
6 Which of following python programming of the list will display given output?
Output: ['apple', 'orange', 'banana', 'watermelon', 'mango', 'cherry']
a) thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "watermelon")
thislist.insert(2, "mango")
thislist.insert(3, "orange")
print(thislist)
b) thislist = ["apple", "banana", "cherry"]
thislist.insert(3, "watermelon")
thislist.insert(2, "mango")
thislist.insert(1, "orange")
print(thislist)
c) thislist = ["apple", "banana", "cherry"]
thislist.insert(2, "watermelon")
thislist.insert(2, "mango")
thislist.insert(3, "orange")
print(thislist)
d) thislist = ["apple", "banana", "cherry"]
thislist.insert(2, "watermelon")
thislist.insert(3, "mango")
thislist.insert(1, "orange")
print(thislist)
7 In a class, some students have written a python program to find the length of a string without using
predefine functions. Find out the correct one.
a) string="Life has been given to make it successful."
i=1
for n in string:
i+=1
print("String Length: ",i)
b) string="Life has been given to make it successful."
i=0
for n in string:
i=+1
print("String Length: ",i)
c) string="Life has been given to make it successful."
i=0
for i in string:
n+=n
print("String Length: ",i)
Page 3 of 17
d) string="Life has been given to make it successful."
i=0
for n in string:
i+=1
print("String Length: ",i)
8 Read the following python scripts carefully and choose best suitable answer-
N = ["apple", "banana", "cherry"]
M = ["mango", "pineapple", "papaya"]
N.extend(M)
print(N)
print(M)
a) List M is appended to List N
b) List N is appended to List M
c) Both a and b
d) None
9 Read the following python scripts carefully and choose best suitable output-
N = ("apple", "banana", "cherry")
for i in range(len(N)):
print(N[i]*(i+1))
a) appleapple
bananabanana
cherrycherry
b) apple
bananabanana
cherrycherrycherry
c) apple
banana
cherry
d) apple
bananabananabanana
cherrycherry
10 Which of the following code is correct to print factorial of a given number using recursive
technique?
A) 1. def recur_factorial(n):
2. if n == 1:
3. return n
4. else:
5. recur_factorial(n-1)
B) 6. def recur_factorial(n):
7. if n == 1:
8. return n
9. else:
10. return n*recur_factorial(n)
C) 11. def recur_factorial(n):
12. if n == 1:
13. return n*recur_factorial(n-1)
14. else:
15. return n
D) 16. def recur_factorial(n):
Page 4 of 17
17. if n == 1:
18. return n
19. else:
20. return n*recur_factorial(n-1)
11 Which of the following program will give correct calculation if valid values are supplied by the
users?
A) # define functions
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
B) # define functions
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
Page 5 of 17
choice = input("Enter choice(1/2/3/4):")
num1 =input("Enter first number: ")
num2 = input("Enter second number: ")
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
C) # define functions
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
D) # define functions
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
Page 6 of 17
return x * y
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
if choice == 1:
print(num1,"+",num2,"=", add(num1,num2))
elif choice == 2:
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == 3:
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == 4:
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
12 Which of the following program will give correct length of the string?
A) defstring_length(str1):
count = 0
for char in str1:
count = 1
return count
print(string_length('python is very easy to learn'))
B) defstring_length(str1):
count = 0
for char in str1:
count = count +2
return count
print(string_length('python is very easy to learn'))
C) defstring_length(str1):
count = 0
for char in str1:
count += 1
return count
print(string_length('python is very easy to learn'))
D) defstring_length(str1):
count = 0
for char in str1:
count += 1
return str1
print(string_length('python is very easy to learn'))
13 Which of the following will give the given output:-
Coce
Page 7 of 17
Coer
Scce
A) defstring_both_ends(str):
if len(str) < 3:
return ''
return str[0:3] + str[-3:]
print(string_both_ends('Computer Science'))
print(string_both_ends('Computer'))
print(string_both_ends('Science'))
B) defstring_both_ends(str):
if len(str) < 2:
return ''
return str[0:6] + str[-2:]
print(string_both_ends('Computer Science'))
print(string_both_ends('Computer'))
print(string_both_ends('Science'))
C) defstring_both_ends(str):
if len(str) < 2:
return ''
return str[0:4]
print(string_both_ends('Computer Science'))
print(string_both_ends('Computer'))
print(string_both_ends('Science'))
D) defstring_both_ends(str):
if len(str) < 2:
return ''
return str[0:2] + str[-2:]
print(string_both_ends('Computer Science'))
print(string_both_ends('Computer'))
print(string_both_ends('Science'))
14 Guneet is writing a Python program to add 'ing' at the end of a given string (length should be at
least 3). If the given string already ends with 'ing' then add 'ly' instead. If the string length of the
given string is less than 3, then the program should not change anything. Select the correct
program out of given options
A) defadd_string(str1):
length = len(str1)
if length > 2:
if str1[3:] == 'ing':
str1 += 'ly'
else:
str1 += 'ing'
return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))
B) defadd_string(str1):
length = len(str1)
if length > 2:
Page 8 of 17
if str1[-3:] == 'ing':
str1 += 'ly'
else:
str1 += 'ing'
return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))
C) defadd_string(str1):
length = len(str1)
if length < 2:
if str1[-3:] == 'ing':
str1 += 'ly'
else:
str1 += 'ing'
return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))
D) defadd_string(str1):
length = len(str1)
if length > 2:
if str1[:3] == 'ing':
str1 += 'ly'
else:
str1 += 'ing'
return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))
15 Aditya is writing a Python program to remove the characters which have odd index values of a
given string. He has written following program codes. Find the correct code to perform the task.
Output Should be
ace
pto
A) defodd_values_string(str):
result = ""
for i in range(len(str)):
if i / 2 == 0:
result = result + str[i]
return result
print(odd_values_string('abcdef'))
print(odd_values_string('python'))
B) defodd_values_string(str):
result = ""
for i in range(len(str)):
Page 9 of 17
if i % 2 == 0:
result = result + str[i]
return result
print(odd_values_string('abcdef'))
print(odd_values_string('python'))
C) defodd_values_string(str):
result = "str"
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result
print(odd_values_string('abcdef'))
print(odd_values_string('python'))
D) defodd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result
print(odd_values_string('abcdef'))
print(odd_values_string('python'))
16 Select the correct output of given Python program
x = 3.1415926
y = -12.9999
print("\nOriginal Number: ", x)
print("Formatted Number with sign: "+"{:+.2f}".format(x));
print("Original Number: ", y)
print("Formatted Number with sign: "+"{:+.2f}".format(y));
print()
A) Original Number: 3.14
Formatted Number with sign: +3.14
Original Number: -12
Formatted Number with sign: -13.
B) Original Number: 3.1415926
Formatted Number with sign: +3.14
Original Number: -12
Formatted Number with sign: -13.00
C) Original Number: 3.5
Formatted Number with sign: +3.1
Original Number: -13
Formatted Number with sign: -13.00
D) Original Number: 3.1415926
Formatted Number with sign: +3.14
Original Number: -12.9999
Formatted Number with sign: -13.00
19 Which of the following program will display all the data from specified file?
A) file = open('data.txt','r')
for each in file:
print (file)
B) file = open('data.txt','w')
for each in file:
print (each)
C) file = open('data.txt','r')
for line in file:
print (each)
D) file = open('data.txt','r')
for each in file:
print (each)
20 Which of the following program will display all the data from specified file?
A) file = open('data.txt','r')
for each in file:
print (file)
B) file = open('data.txt','w')
for each in file:
print (each)
C) file = open('data.txt','r')
for line in file:
print (each)
Page 11 of 17
D) file = open('data.txt','r')
for each in file:
print (each)
21 After execution of following python statements, all these three lines will be written of the file
data.txt. Select the correct format in which data will be written in the file.
file = open('data.txt','w')
file.write("This is the write command\n")
file.write("It allows us to write in a particular file\n")
file.write("It allows us to \t\twrite in a particular file\n")
file.close()
A) This is the write command\n
It allows us to write in a particular file\n
It allows us to \t\twrite in a particular file\n
B) This is the write commandIt allows us to write in a particular fileIt allows us to write in a particular
file
C) This is the write command
It allows us to write in a particular file
It allows us to write in a particular file
D) This is the write command It allows us to write in a particular file It allows us to write in a particular
file
22 If a file contains following data-
Everyone has something to say. But no one is listeningwhat has been told
already.
D) Everyone has something to say. But no one is listening what has been told already.
23 Which of the following is the correct definition of file mode?
A) "r" - Read - Default value. Opens a file for reading, error if the file does not exist
"a" - Append - Opens a file for appending, does not create the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
B) "r" - Read - Default value. Opens a file for reading, error if the file does not exist
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing and read mode, creates the file if it does not exist
C) "r" - Read - Default value. Opens a file for reading, error if the file does not exist
Page 12 of 17
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
D) "r" - Read - Opens a file for reading and writing, error if the file does not exist
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
24 f = open("data.txt", "r")
print(f.read(5))
print(f.read(10))
Choose the best suitable answer for given above code snippets if data.txt contains following data
A) Each of
us should follow
B) Each of
us should follow
C) Each
us should
D) Each
of us shou
25 Which of the program is correct for counting total no of characters in a text file?
A) with open("file.text", "r") as file:
data = file.read()
count=0
for ch in data:
count+=1
print (count)
Page 14 of 17
B) ['Name', 'Branch', 'Year', 'CGPA']
['Nikhil', 'COE', '2', '9.0']
['Sanchit', 'COE', '2', '9.1']
['Aditya', 'IT', '2', '9.3']
['Sagar', 'SE', '1', '9.5']
['Prateek', 'MCE', '3', '7.8']
['Sahil', 'EP', '2', '9.1']
Considering the above data in file, select the best output for given program-
fileptr = open("data.txt","r")
print("The filepointer is at byte :",fileptr.tell())
content = fileptr.read();
print("After reading, the filepointer is at:",fileptr.tell())
A) The filepointer is at byte : 0
After reading, the filepointer is at: 0
B) The filepointer is at byte : 56
After reading, the filepointer is at: 0
C) The filepointer is at byte : 0
After reading, the filepointer is at: 56
D) The filepointer is at byte : 56
After reading, the filepointer is at: 56
29 Krrishnav is looking for his dream job but has some restrictions. He loves Delhi and would take a
job there if he is paid over Rs.40,000 a month. He hates Chennai and demands at least Rs. 1,00,000
to work there. In any another location he is willing to work for Rs. 60,000 a month. The following
code shows his basic strategy for evaluating a job offer. [1X5=5]
Code:
pay= location=
if location == "Mumbai":
print ("I’ll take it!") #Statement 1
elif location == "Chennai": if pay <
Page 15 of 17
100000:
print ("No way") #Statement 2 else:
print("I am willing!") #Statement 3 elif location
== "Delhi" and pay > 40000:
print("I am happy to join") #Statement 4 elif pay >
60000:
print("I accept the offer") #Statement 5 else:
print("No thanks, I can find something
better")#Statement 6
On the basis of the above code, choose the right statement which will be executed when different
inputs for pay and location are given.
A) Input: location = "Chennai”, pay = 50000
a. Statement 1
b. Statement 2
c. Statement 3
d. Statement 4
B) Input: location = "Surat" ,pay = 50000
a. Statement 2
b. Statement 4
c. Statement 5
d. Statement 6
a Statement 1
b. Statement 2
c. Statement 4
d. Statement 6
30 Consider the following code and answer the questions that follow: [1X2=2]
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}
Library ={'5':'Madras Diaries','6':'Malgudi Days'}
A) Ramesh needs to change the title in the dictionary book from „Crime‟ to „Crime Thriller‟. He has
written the following command:
Book[„Crime‟]=‟Crime Thriller‟
But he is not getting the answer. Help him choose the correct command:
a. Book[2]=‟Crime Thriller‟
b. Book[3]=‟Crime Thriller‟
c. Book[2]=(‟Crime Thriller‟)
Page 16 of 17
d. Book[3] =(„Crime Thriller‟)
B) The command to merge the dictionary Book with Library the command would be:
a. d=Book+Library
b. print(Book+Library)
c. Book.update(Library)
d. Library.update(Book)
Page 17 of 17