0% found this document useful (0 votes)
43 views

Dictionary Assignment

Uploaded by

Rekha Verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Dictionary Assignment

Uploaded by

Rekha Verma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Class Test -Computer Science

Class-XII M.M:50

1. State True or False: “Keywords can be used as identifiers in Python.” (1)


2. Which of the following is an invalid identifier in Python? (1)
(a) Roll_No (b) Salary
(c) Account No (d) EmpID
3. Which of the following will delete key-value pair for key = “Red” from a dictionary D1? (1)
(a) delete D1(“Red”) (b) del.D1(“Red”)
(c) del D1[“Red”] (d) del D1
4. What will be the output of the following statement: (1)
print(3-10**2+99/11)
(a) 80 (b) 81
(c) -81 (d) 81.0
5. What will be the output of the following code? (1)
Str1= ‘My name is digital’
Str2=Str1[3:7]
strlen = len(Str2)
print(strlen)
(a) 4 (b) 14
(c) 24 (d) 34
6. Which of the following functions is used to write data in the binary mode? (1)
(a) write (b) output
(c) dump (d) send
7. Fill in the blank: (1)
______ keyword is used to display non-repeated values in MySQL.
(a) Unique (b) Remove
(c) Distinct (d) All
8. Which of the following commands will change row(s) of the table from MySQL database? (1)
(a) REPLACE TABLE (b) CHANGE TABLE
(c) UPDATE (d) ALTER TABLE
9. Which of the following statement(s) would give an error after executing the following code? (1)
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
(a) Statement 1 (b) Statement 2
(c) Statement 3 (d) Statement 4
10. Fill in the blank: (1)
A.1
_________ is a table constraint that will prevent the entry of duplicate rows.
(a) Primary Key (b) NULL
(c) Unique (d) Distinct
11. Which of the following is the correct syntax of file object ‘fobj’ to write sequence data type using
writelines() function? (1)
(a) file.writelines(sequence)
(b) fobj.writelines()
(c) fobj.writelines(sequence)
(d) fobj.writeline()
12. Fill in the blank: (1)
HAVING clause is used in combination with______________clause.
(a) GROUP BY (b) Where
(c) IN (d) Order By
13. Which statement consists of a logical operator? (1)
(a) a+b**c (b) a >b:
(c) a and b not c (d) 2 in a
14. Which of the following function can work with NULL values in a database? (1)
(a) avg() (b) sum()
(c) count(*) (d) total(*)
15. Which command is used for counting the number of rows in a database? (1)
(a) row (b) rowcount
(c) count() (d) row_count
16. What will be the output for the following Python statements? (1)
D= {“Amit”:90, “Reshma”:96, “Suhail”:92, “John”:95}
print(“John” in D, 90 in D, sep= “#”)
(a) True#False (b)True#True (c) False#True (d) False#False
17. Choose the correct command to delete an attribute A from a relation R. (1)
(a) ALTER TABLE R DELETE A
(b) ALTER TABLE R DROP A
(c) ALTER TABLE DROP A FROM R
(d) DELETE A FROM R
18. Identify the errors in the following code: (1)
MyTuple1=(1, 2, 3) #Statement1
MyTuple2=(4) #Statement2
MyTuple1.append(4) #Statement3
print(MyTuple1, MyTuple2) #Statement4
(a) Statement 1 (b) Statement 2 (c) Statement 3 (d) Statement 2 &3
Q17 and 18 are Assertion and Reason-based questions. Mark the correct choice:
(i) Both A and R are true and R is the correct explanation for A
(ii) Both A and R are true and R is not the correct explanation for A
(iii) A is True but R is False
(iv) A is False but R is True
19. Assertion (A): Function can take input values as parameters, execute them and return output (if required)
to the calling function with a return statement. (1)
Reason (R): A function in Python can return multiple values.
20. Assertion (A): Pickle in Python is primarily used in serializing and deserializing a Python object structure.
Reason (R): pickle.dump() method is used to write the object in file and pickle.load() method is used to
read the object from pickled file. (1)
A.2
SECTION – B
21. Shristi has written a Python program to add all the numbers of the list. Her code is having errors. Rewrite the
correct code and underline the corrections made. (2)
define sum(numbers):
total = 0
for x in numbers
total += x
returns total
print(sum([4, 6, 3, 5, 6]))
22. (a) Given is a Python string declaration: (2)
mySubject = "Computer Science with Python"
(i) Write the output of: print(mySubject[-27:-10:2])
(b) Write the output of the code given below:
>>>a=[10,20,30,40,50,60,70]
>>> a[3:5]=[100,1000]
>>> a[3:5]=[10000]
>>> print(a)
23. Write the output of the given code: (2)
def Display(l):
L2=[]
for n in l:
if n % 2 ==0:
l2.append
(n)
return L2
print(Display([100, 228, 333, 432, 509, 60, 787, 800, 967]))
OR
Predict the output of the Python code given below:
t1=(10,20,"book",30,9.5,"item",[12,13],(3,4),30,5,30)
print(t1.index(20))
print(t1.index(30))
print(t1.count(30))
print(t1[–8:–4])

24. Write the output of the queries (i) to (iv) based on the table, STOCK given below: (2)
Table: STOCK

ItemNo Item Dcode Qty UnitPrice StockDate


5005 Ball Pen 0.5 102 100 16 2010-03-31
5003 Ball Pen 0.25 102 150 20 2010-01-01
5002 Gel Pen Premium 101 125 14 2010-02-14
5006 Gel Pen Classic 101 200 22 2009-01-01
5001 Eraser Small 102 210 5 2009-03-19
5004 Eraser Big 102 60 10 2009-12-12
5009 Sharpener Classic 103 160 8 2009-01-23
Table: DEALERS

A.3
Dcode DName
101 Reliable Stationers
103 Classic Plastics
102 Clear Deals
(i) SELECT Dcode, MAX(UnitPrice) FROM STOCK GROUP BY Dcode;
(ii) SELECT COUNT(DISTINCT Dcode) FROM STOCK;
(iii) SELECT Qty*UnitPrice FROM STOCK WHERE ItemNo=5006;
(iv) SELECT MIN(StockDate) FROM STOCK;
Section- C
25. Write a user-defined function Count_H_T() in Python that displays the number of lines starting with ‘H’ and
‘T’ in the file “Poem.txt”. Example, if the file contains: (3)
Here we go round the mulberry bush,
The mulberry bush,
The mulberry bush.
Here we go round the mulberry bush
On a cold and frosty morning.
The line count should be 4.
OR
Write a function Replace_Space() in Python which should read each character of a text file “MYFILE.TXT”
and then replace all spaces from text with dash (-).
Example:
If the file content is as follows:
The relative paths are relative to current working directory.
The Replace_Space() function should display the output as:
The-relative-paths-are-relative-to-current-working-directory.

26. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations MOBILEMASTER & MOBILESTOCK
given below: (3)
Table: MOBILEMASTER

M_Id M_Company M_Name M_Price M_Mf_Date


MB001 Samsung Galaxy 4500 2013-02-12
MB003 Nokia N1100 2250 2011-04-15
MB004 Micromax Unite3 4500 2016-10-17
MB005 Sony XperiaM 7500 2017-11-20
MB006 Oppo SelfieEx 8500 2010-08-21
Table: MOBILESTOCK

(i) S_Id M_Id M_Qty M_Supplier SELECT


S001 MB004 450 New Vision
S002 MB003 250 Praveen Gallery
S003 MB001 300 Classic Mobile Store
S004 MB006 150 A-one Mobiles
S005 MB003 150 The Mobile
S006 MB006 50 Mobile Centre
M_Company, M_Name, M_Price,M_Qty FROM MOBILEMASTER MM, MOBILESTOCK
MS, WHERE MM.M_ID= MS.M_ID;
(ii) SELECT MAX(M_Price) FROM MOBILEMASTER WHERE M_Name LIKE "S%";
(iii) SELECT M_Supplier, M_Qty FROM MOBILESTOCK WHERE M_Id ="MB003";

A.4
(iv) SELECT M_Company FROM MOBILEMASTER WHERE M_Price BETWEEN 3000 AND 5000;
(b) Write a command to open an existing database ‘Stock’.
27. Write the definition of a method COUNTNOW(PLACES) to find and display those place names in which there are
more than five characters after storing the name of places in a dictionary. (3)
For example, if the dictionary PLACES contains:
{'1': "DELHI", '2': "LONDON", '3': "PARIS", '4': "NEW YORK", '5': "DUBAI"}
The following output should be displayed:
LONDON NEW YORK
28.Predict the output of the code given below: (2)

def Change(s):

k =len(s) m=" "

for i in range(0,k): if(s[i].isupper()):


m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'$'
print(m)
Change('IPv6 128-bit')

29. What is the function of csv.writer() function? (5)


Write a program in Python that defines and calls the following user-defined functions:
(i) AddRecord() – To accept and add data of Mobile phones to a CSV file ‘Mobile_Phones.csv’. Each record
consists of a list with field elements as ModelNo, MobileName, Manufacturer and Price to store model
number, mobile name, manufacturer and price respectively.
(ii) Find() – To search the records of mobiles manufactured by Apple present in the CSV file named
‘Mobile_Phones.csv’.
OR
What is the benefit of using “with open()” method over “open()” method while opening a file?
Write a program in Python that defines and calls the following user-defined functions:
(i) Add_Item() – To accept and add data of stationery items to a CSV file ‘Stationery.csv’. Each record
consists of a list with field elements as Item_Id, Item_name and Item_price to store item id,
item_name and item_price.
(ii) Count() – To count the total number of stationery items in the CSV file.
30. Krishna, working as a computer professional in a hospital, creates a table OPD to store records of patients
registered in the OPD section. A sample of the records is given below: (1+1+2)

A.5
Table: OPD
Reg Name Department Dateof_R Charg Ge Roo
No eg es nd m No
er

R0123 Arpita Gen. 2022-01- 500 M 10


Physician 21

R0124 Jai ENT 2022-10- 300 M 15


12

R0125 Kamal Orthopaedic 2022-02- 500 M 11


19

R0126 Arun Paediatrician 2022-07- 500 M 12


11

R0127 Neha ENT 2022-01- 300 F 15


12

R0128 Neetu ENT 2022-09- 300 F 15


24

R0129 Ankit Cardiology 2022-02- 800 F 20


20

Based on the data given above, answer the following questions:

(i) If the table “OPD” is to be linked with another table “Registration” in the same database named
“Hospital”, then identify the most appropriate column which can be used as a Foreign key in the
“Registration” table.

(ii) What is the cardinality and degree of the given table?

(iii) Write the statements to:

(a) Insert the following record into the table: RegNo–R130, Name–Naman, Age–30, Department–
ENT, Dateof_Reg–2022-10-10, Charges–700, Gender–M.

(b) Increase the OPD Charges of the ENT department by ` 200’.

OR (Option for part iii only)

(iii) Write the statements to:

(a) Delete the column RoomNo from the table OPD.

(b) Add a new column Panel_Discount in the table with datatype as Varchar with 50 characters.

31. Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a binary
file ‘Result.dat’ with Student_Id, St_Name, Game_Name and Result to store the results of students in
different sports events. After the event has been completed, he now wants to display the records of those
students who won the game, which is inserted in the Result field with ‘Won’ and ‘Loss’ data. As a Python
expert, help him complete the following code based on the requirement given above: (1+1+1+1)

import rec=[]

A.6
while True:
Student_Id=int(input(("Enter Student Id:")))
St_name=input("Enter name:")
Game_Name=input("Enter Salary:")
Result= input(“Enter Result:”)
data=[Student_Id, St_Name, Game_Name,Result]
rec.append(data)
Choice=input("Wish to enter more records: Y/N")
if Choice.upper()=='N':
break
f1= #Statement2
pickle.dump(rec,f1)
print("Record added:")
fout=open("Result.dat",'rb')
res= #Statement 3
count=0
for i in res:
if : #Statement 4
st_id=i[0]
st_name=i[1]
game=i[2]
result=i[3]
count+=1
print(st_id,st_name,game,result)
print("Total students are", count)
fout.close()
(i) Write a statement to import the module. (Statement 1)
(ii) Write a statement to open a binary file in write mode. (Statement 2)
(iii) Write the correct statement required to load the file. (Statement 3)
(iv) Write a statement to check if result field contains ‘Won’ or ‘won’. (Statement4)

A.7
A.8

You might also like