0% found this document useful (0 votes)
25 views7 pages

Solution 1435071

Uploaded by

srivini0310
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views7 pages

Solution 1435071

Uploaded by

srivini0310
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Solution

QUARTELY PAPER

Class 12 - Computer Science


Section A
1. Read the text carefully and answer the questions:
Riya wrote a program to print the Fibonacci series. But some words or lines had missing. Help her to execute the given program.

n = int(input("How many terms"))


n1, n2 = 0,1
count = 0
if n <= 0:
print ("Please enter a positive number")
elif
print("fibonacci sequence upto", n, " : ")
print(________)
else :
print("Fibonacci sequence :")
while count < n :
print (n1)
n3 = ________
n1 = n2
n2 = ________
count = count + 1

(i) (colon)
(ii) n == 1 :
(iii)n1
(iv)n1 + n2
2. Read the text carefully and answer the questions:
Below is a program to enter a string and display new string. Answer the questions that follow to execute the program successfully.
35

def make(str1):
newstr = " "
count = 0
for i in strl:
if count %2...0:
newstr = newstr + str (count)
else:
if islower(.....):
newstr = newstr + upper ...
else:
newstr = newstr + i
count = .....
newstr = newstr + str 1[:1]
print("The new string is:", .....)
make("aRiHaNT")

(i) !=
(ii) i
(iii)Count +1
(iv)newstr
3. Read the text carefully and answer the questions:
Here is a program to check whether a passed string is palindrome or not. Answer the below questions to execute the program successfully.

def isPalindrome():
strl = input("Enter string")
left_pos = 0
right_pos = len(strl)...
while ....... :
if not strl [left_pos]
= strl [right_pos]:
.......
left_pos + = 1

1/7
.......
.......

(i) right_pos>= left_pos


(ii) return False
(iii)right_pos += 1
(iv)True
4. Read the text carefully and answer the questions:
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 ₹40000 a month. He hates
Chennai and demands at least ₹100000 to work there. In any another location, he is willing to work for ₹60000 a month. The following code shows his basic
strategy for evaluating a job offer.

pay =________
location = ________
if location = = "Mumbai":
print ("I’ll take it!") #Statement 1
elif location == "Chennai":
if pay < 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.
(i) (c) Statement 2
Explanation: When user enters input as location = Chennai and pay =50000, then location = "Chennai" condition will be true. After that, pay <
100000 : will be check it also true, so print ("No way") statement 2 will be execute.
(ii) (b) Statement 6
35

Explanation: When location = "Surat", pay = 50000 entered by user then statement 6 will be execute.
(iii) (b) Statement 6
Explanation: When location = "Any Other City", pay =1
entered by user then statement 6 will be execute because it does not satisfied any given condition.
(iv) (a) Statement 4
Explanation: When location = "Delhi", pay = 50000
entered by user then statement 4 will be execute.
(v) (b) Statement 5
Explanation: When location = "Lucknow", pay = 65000
entered by user then statement 5 will be execute.
5. Read the text carefully and answer the questions:
In a Database, there are two tables with the instances given below:
Table : STUDENTS

ADMNO NAME CLASS SEC RNO ADDRESS PHONE

1211 MEENA 12A D 4 A-26 3245678

1212 VANI 10A D 1 B-25 5456789

1213 MEENA 12B A 1 NULL NULL

1214 KARISH 10B B 3 AB-234 4567890

Table : SPORTS

ADMNO GAME COACHNAME GRADE

1215 CRICKET MR. RAV A

1213 VOLLEYBALL MR.AMANDEEP B

1211 VOLLEYBALL MR.GOVARDHAN A

1212 BASKET BALL MR. TEWARI B

(i) (c)

2/7
SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
STUDENTS.ADMNO=SPORTS.ADMNO AND ADDRESS IS NOT NULL;

Explanation: For writing the query it is required to select NAME and GAME field from STUDENTS table and SPORTS table using an equi join
operation.
(ii) (c)

ALTER TABLE STUDENTS DROP PHONE;

Explanation: ALTER command is used, if there is any updation required in definition of a table. DROP clause is used with ALTER command to
delete a column from a table.
Syntax to delete any column from table is

ALTER TABLE <table_name> DROP <column_name>

(iii) (c)

SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE "12%" AND STUDENTS.ADMNO =SPORTS.ADMNO;

Explanation: One field is from STUDENTS table and one is from SPORTS table, equi join will be used and to select any kind of pattern in
character field LIKE clause is used.
(iv) (c)

SELECT C0UNT(*) FROM STUDENTS, SPORTS WHERE GAME="VOLLEYBALL" AND STUDENTS.ADMNO=SPORTS.ADMNO;

Explanation: To count number of students play volleyball again we need to apply join and only those students are required to be counted who are
present in both tables.
COUNT(*) will count all rows.
(v) (b) A and D
Explanation: Both (A) and (D) queries will give same output. Because in (D) query, same tables and conditions are used but instead of using table
35

name its alias (short name) has been declared. For STUDENTS - ST and for SPORTS - SP.
6. Read the text carefully and answer the questions:
Arun, during Practical Examination of Computer Science, has been assigned an incomplete search() function to search in a pickled file student.dat. The file
student.dat is created by his teacher and the following information is known about the file.
File contains details of students in [roll_no, name, marks] format.
File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student is written in the binary file using dump().
Arun has been assigned the task to complete the code and print details of roll number 1.

def search():
f = open("student.dat",___) #Statement 1
____: #Statement 2
while True:
rec = pickle.____ #Statement 3
if (____): #Statement 4
print(rec)
except:
pass
____ #Statement 5

(i) (c) rb
Explanation: Arun should open the file in rb mode in Statement 1. This mode opens a file for reading only in binary format.
(ii) (a) try
Explanation: try is used at blank space in line marked as Statement 2.
(iii) (c) load(f)
Explanation: load (f) is used at blank space in Statement 3. This method is used to load data from a binary file.
(iv) (b) rec [0] ==1
Explanation: rec[0]==1 condition will be suitable code for blank space in line marked as Statement 4.
(v) (d) f.close()
Explanation: Opened file is closed by calling the close() method of its file objects.
So, code is f.close() where f is file object.
Section B

3/7
7. (a) 4.5 % 3
Explanation: The expression 4.5 % 3 is evaluated as 4.5 % 3.0 (that is, automatic conversion of int to float).
8. (a) [30, 40, 50]
Explanation: [30, 40, 50]
9.
(b) False
Explanation: False
10.
(d) imaginary part
Explanation: imaginary part
11. (a) shallow copy
Explanation: shallow copy
12.
(d) None of these
Explanation: None of these
13. (a) Line 4
Explanation: The num list has 5 elements only. Since, the list indexing starts from 0, the print(num[5]) statement looks for sixth element of the list which
does not exist.
Section C
14.
(b) Both A and R are true but R is not the correct explanation of A.
Explanation: The tuple items cannot be deleted individually by using the del keyword as tuple is immutable. To delete an entire tuple, we can use the del
keyword with the tuple name.
15. (a) Both A and R are true and R is the correct explanation of A.
Explanation: The intersection_update() method is different from the intersection() method since it modifies the original set by removing the unwanted
items, on the other hand, the intersection() method returns a new set removing the unwanted items.
Section D
16. State True or False:
(i) (a) True
35

Explanation: True, A string can be surrounded by three sets of single quotation marks or by three sets of double quotation marks.
(ii) (a) True
Explanation: True, it ignores all null values.
(iii) (b) False
Explanation: False, The SELECT DISTINCT statement is used to return only distinct (different) values.
Section E
17. Fill in the blanks:
(i) 1. string slice
2. sting slicing
3. sliced string
(ii) 1. Keyword
(iii) 1. Parameters
2. Formal parameters
3. Formal arguments
Section F
18.
(d) Relations
Explanation: Relations
19.
(c) Having
Explanation: The HAVING clause is closely associated with the GROUP BY clause.
Section G
20.
(b) return number
Explanation: return number
Section H
21. In program 1, the complete module Allchecks.py must have been imported by the statement import Allchecks. So, a namespace is created and we need to
specify the module name also with the function name.
Whereas in program 2, only the function checkMain() must have been imported by the statement From Allchecks import checkMain(). So, only the
checkMain() function is imported into the namespace of the program 2 and hence can be used independently without its module name.

4/7
22. We can define the functions hello() and world() in a python(.py) file and name the file as "helloworld" and use the helloworld module in another program.
E.g : We can call hello() function as helloworld.hello() in another program.
23. i. The statement for i in range(len(words), 0, -1) will give error because, words[i] will access the first value as words[len(words)] and it is not a valid syntax
for the list words.
Valid indexes are from 0 to len(words) -1
ii. If we correct the above line of code as for i in range( len(words) - 1, 0, -1), still it will not print the first word as ending index given in expression
range(len(words) - 1, 0, -1) and ending index is not included in the range() result. The corrected statement should be for i in range(len(words) -1, -1, -1) :
24. i. L [3 : 4] = ['that']
L [1 : 2] = [['are', 'a' ]]
L [3 : 4] + L [1 : 2] = ['that', ['are', 'a']]
ii. False: The string "few" is not an element of this range. L[2 : 3] returns a list of elements from L - [['few', 'words']], this is a list with one element, a list.
iii. True: L[2] returns the list ['few', 'words'], "few" is an element of this list.
iv. L [2] = [ ’few', 'words']
L [2] [1:] = ['words']
v. L [1] = [ 'are' , 'a' ]
L [2] = ['few', ’words']
L [1] + L [2] = ['are' , 'a', ' few', 'words']
25. i. hellohellohello 123
10 helloworld
ii. h :e :l :l :o :t :o : :P :y :t :h :o :n :w :o : r :l :d :
iii. he hello wor ld
w ll
llo wo or
26. The lists and strings are different in following ways:
i. The lists are mutable sequences while strings are immutable.
ii. In consecutive locations, a string stores the individual characters while a list stores the references of its elements.
iii. Strings store single type of elements - all characters while lists can store elements belonging to different types.
27. Line = "This is going to be fun"
Lst = Line.split()
total = 0
count = 0
35

for w in Lst:
count = count + 1
lenword = len(w)
total = total + lenword
avg = total/count
print("Original line:", Line)
print ("List of words:", Lst)
print("Total length of all words :", total)
print("Average length of all words:", avg)

Output:
('Original line:', 'This is going to be fun')
('List of words:', ['This', 'is', 'going', 'to', 'be', 'fun'])
('Total length of all words :', 18)
('Average length of all words:', 3)

28. def InsertQ(Names):


Name=raw_input("enter Name to be inserted: ")
Names.append(Name)
def DeleteQ(Names):
if (Names==[]):
print "Queue empty"
else:
print "Deleted Player’s Name is: ",Names[0]
del(Names[0])

29. from bisect import bisect


def insert_delete(numlist , number):
insert_index = bisect(numlist , number)
numlist.insert(insert_index,number)
print “List after Insertion”
print numlist
numlist.remove(number)

5/7
print “List after Deletion”
print numlist

max_range = input(“Enter Count of numbers: ”)


numlist = [ ]
for i in range(0, max_range):
numlist.append(input(“?”))
numlist.sort()
num = input(“Enter the number to be inserted and deleted”)
insert_delete(numlist, num)
30. def prime(n) :
for num in range (2, n) :
is_prime = 1
for i in range (2, num):
if num % i == 0:
is_prime = 0
if is_prime == 1:
print (num)
31. When import math statement is used, a new namespace sets up in our working environment with the same name as that of the math module and code of the
module is interpreted and executed. All the defined functions, constants and variables of the math module are available to our program. There is no need to
import the objects of modules everytime they are used.
Whereas when we use from math import * statement no new namespace is created. Only the functions and variables of the imported module are added to the
namespace of the program. If there are two variables with same name, one in the program and other in the imported module then the variable of the imported
module is hidden by the program variable. We need to import every object we are using in the code.
32. i. 6
ii. 42
{(1, 2) : 24, (4, 2, 1) : 10, (1, 2, 4) : 8}
33. i. 21
ii. -1
iii. 6
iv. False
v. False
35

vi. 68
vii. 86
viii. True
34. The globals( ) and locals( ) functions can be used to return dictionary of the names of objects in the global and local namespaces depending on the location from
where the functions are called.
If locals() is called from within a function, it will return dictionary of all the names of objects that can be accessed locally from that function. e.g :
def get_name():
name = "Sachin"
print("local variables : ", locals())
get_name()
Above code gives output "local variables : {'name' : 'Sachin'}

If globals() is called from within a function, it will return dictionary of all the names that can be accessed globally from that function. If globals() is called
outside the function, The return type is dictionary of all the objects in the program.
35. a. Primary Key of CARDEN = Ccode CARDEN Alternate Key = CarName: Primary key of Customer = Code Alternate Key of Customer = Cname 2
b. i. SELECT CarName FROM CARDEN WHERE Color = "SILVER";
ii. SELECT CarName, Make, Capacity FROM CARDEN ORDER BY Capacity DESC;
iii. SELECT MAX(Charges) FROM CARDEN;
iv. SELECT Cname, CarName From CUSTOMER CARDEN, WHERE CUSTOMER. Ccode = CARDEN. Ccode;
c. i. 4

ii. MAX(Charges) MIN(Charges)

35 12
iii. 5
iv. SX4
C Class
36. i. SELECT TNAME, CITY, SALARY FROM TRAINER ORDER BY HIREDATE
ii. SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE BETWEEN '2001-12-01' AND '2001-12-31'
SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE > = '2001-12-01' AND HIREDATE < = '2001-12-31';
iii. SELECT TNAME, HIREDATE, CNAME, STARTDATE FROM TRAINER.COURSE WHERE TRAINER.TID= COURSE.TID AND FEES < = 10000;
iv. SELECT CITY, COUNT(*)) FROM TRAINER GROUP BY CITY;

v. TIDTNAME

6/7
v.
103 DEEPTI

106 MANIPRABHA
vi. DISTINCT TID
101
103
102
104
105

vii. TIDCOUNT(*) MIN(FEES)

101 2 12000

viii. COUNT(*) SUM(FEES)

4 65000

35

7/7

You might also like