Dictionary Assignment
Dictionary Assignment
Class-XII M.M:50
24. Write the output of the queries (i) to (iv) based on the table, STOCK given below: (2)
Table: STOCK
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
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):
A.5
Table: OPD
Reg Name Department Dateof_R Charg Ge Roo
No eg es nd m No
er
(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.
(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) 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