Set 1
Set 1
Class:XII Session:2023-24computerscience(083)
2. Whichoperatorperformspatternmatching? [1]
a) Likeoperator B)Betweenoperator
c) Noneofthese d) Existsoperator
3. Whichofthefollowingiscorrecttoretrieveanycharacteratindex'i'instring's'? [1]
a) S._Getitem_(I B)S.Getitem(I-1)
)
D)S.Getitem(I)
C) S._Getitem_(I-
1)
4. Whatwillbetheoutputofthefollowingcode? [1]
Value=50
Defdisplay(N
):Globalval
ue
Value=25
Ifn%7==0:
Value=Value+N
else:
Value=Value-N
r -------------------------------,
Print(Value,End= )
11#11display(20}
Print(Value)
A)5#50#
B)50#50
C)50#5
D}50#30
5. Signalsgeneratedbyanoperatingsystemtosenditoverphonelinemustbefurther [1]
Converted Intoa/An
a) Analogsignal B)Microwave
C)Acsignal D)Digitalsignal
6. Toreadthenextlineofthefilefromafileobjectinfi,Weuse [1]
a) Infi.Read() B)Infi.Readlines()
C)Infi.Readline() D)Infi.Read(All)
a) Localhost B)Globalhost
C)Host D)Noneofthese
8. Whichofthefollowingsublanguagesofsqlisusedtodefinethestructureofthe [1]
Relation,Deletingrelationsandrelatingschemas?
a) Relationalschema B)DDL(Datadefinitionlanguage)
c) DML(Datamanipulati d) Query
onlanguage)
9. Whichfunctionisusedtoreadallthecharacters? [1]
Page2
L -------------------------------
r -------------------------------,
a) Readcharacters( ) B)Read()
c) Readchar( d) Readall()
)
Defadd(Numl,Num2
):Sum=Numl+Nu
m2
Page3
L -------------------------------
r -------------------------------,
Sum=Add(20,30)Prin
t(Sum)
a) None B)Null
C)50 D)O
a) 4 B)3
C)1 D)2
a) Functionsdon'tprovidebetter b) Functionsarereusablepiecesofp
modularityforyourapplicatio rograms
n
c) Youcan'talsocreateyourown d) Allofthese
functions
a) Expression B)Typeconversion
C)Operator D)Comparison
15. Fillintheblanks:
Operator Isusedtomatchavaluesimilartospecificpatterninacolumnusing
Page4
L -------------------------------
r -------------------------------,
d_. [1]
16. Cdmastandsfor?
a) Calldivisionmultipleaccess B)Channeldivisionmultipleaccess
[1]
C)Celldivisionmultipleaccess D)Codedivisionmultipleaccess
Page5
L -------------------------------
r -------------------------------,
17. Assertion(A):Theintersection_Update()Methodisdifferentfromtheintersection() [1]
Method.
Reason(R):Intersection_Update()Methodmodifiestheoriginalsetbyremovingtheunwa
nted Items.
a) Bothaandraretrue b) Bothaandraretruebutrisnotthec
Andristhecorrectexplanation orrectexplanationofa.
ofa.
Sectionb
19. Answer: [2]
(i)
I.
Whatismodulation? [1]
(ii) OR
i. Whatarethebasicmethodsofcheckingerrorsinthedatabeingtra [2]
nsmittedovernetworks?
Page6
L -------------------------------
r -------------------------------,
Id Idofthelocation
Bidycode Code Ofthebuilding
Room Typeofrooms
Capacity Capacityoftheroom
21. [2]
Rewritethefollowingcodeinpythonafterremovingallsyntaxerror(S)
.Underlineeachcorrectiondoneinthecode.
30=To
Forkinrange(O,To
)Ifk%4==0:
Print(K*4)
Page7
L -------------------------------
r -------------------------------,
Else:
Print(K +3)
OR
Whatistheoutputofthe Following?
True=Falsewhi
letrue:Print(Tr
ue)Break
23. Differentiatebetweenalogicalerrorandsyntaxerror.Also,Givesuitableexamplesof[2]
Eachinpython.
OR
Asimmutabletypescannotbechangedinplacethenthefollowingcodeshouldraiseanerr
orwhichmodifiesanint(Animmutabletype)Variable.Butitproducesnoerror.Why?
A=22
A+=2
OR
Atextfile(Sayan.Txt)Containsalphanumerictext.Writeaprogramthatreadsthistextfilea
ndprintsonlythenumbersordigitsfromthefile.
Page9
L -------------------------------
r -------------------------------,
Sectionc
D ie={'A':1,1 :
2,1 3,1 :4}
b1 c1 d1
Print(Die)
If'a'indie:
Deldic[1
]
a1
Print(Die)
PName VARCHAR(20)
DOJ Date
SAL NUMBER
i. Displaythenameoftheprogrammer,Whichhasthehighestsalary.
ii. Updatethesalaryofallprogrammerby2000,Whosenamestartwithletterr.
OR
Whataretuplesinasqltable? Writeasuitableexamplewitha
Sqltabletoillustrateyouranswer.
Page10
L -------------------------------
r -------------------------------,
29. Atextfile 11Quotes.Txt11 [3
Hasthefollowingdatawritteninit:Livingalifeyoucanbep ]
Spendingyourtimewithpeopleandactivitiesthatareimportanttoyoust
anding Upforthingsthatare Rightevenwhenit'shard
Becomingthebestversionofyou
Writeauserdefinedfunctiontodisplaythetotalnumber
Ofwordspresentinthefile.
30. Writeafunctionthattakesasortedlistandanumberasanargument.Searchforthenum [3]
berinthesortedlistusingbinarysearch.
Page11
L -------------------------------
r -------------------------------,
Sectiond
31. .
Ayurvedatrainingeducationalinstituteissettingupitscentreinhyderabadwith [5]
Threespecializeddepartmentsfororthopaedics,Neurologyandpaediatricsalong
withanadministrativeofficeinseparatebuildings.Thephysicaldistancesbetween
thesedepartmentbuildingsandthememberofcomputerstobeinstalledinthese
Departmentsandadministrativeofficesaregivenasfollows.You,Asanetworkex
perthavetheshortestdistancesbetweenvariouslocationsinmeters:
Administrativeofficetoorthopaedicsunit 55
Neurologyunittoadministrativeoffice 30
Orthopedicsunittoneurologyunit 70
Paediatricsunittoneurologyunit 50
Pediatricsunittoadministrativeoffice 40
Paediatricsunittoorthopaedicsunit 110
Thenumberofcomputersinstalledatthevariouslocationisasfollows:
Paediatricsunit 40
Administrativeoffice 140
Neurologyunit 50
Orthopedicsunit 80
IAdministrativeofficeI
IOrthopaedicsunit I
J NeurologyunitJ
i. Suggestthemostsuitablelocationforthemainserverofthis
Institutiontogetefficientconnectivity.
ii. Suggestthecablelayoutforeffectivenetworkconnectivityofthebuildingha
vingaserverwithalltheotherbuildings.
Page12
L -------------------------------
r -------------------------------,
iii. Suggestadevicetobeinstalledineachofthesebuildingforconnectingc
omputersinstalledwithinthebuildingoutofthefollowing:
• Gateway
• Modem
• Switch
Page13
L -------------------------------
r -------------------------------,
iv. Suggestthetopologyofthenetworkandnetworkcableforefficientlyconnecti
ngineachofthebuildingoneofthefollowing:Topologies:Bustopology,Start
opology,Networkcable:Singlepairtelephonecable,Coaxialcable,Ethernetcab
le.
32. . Writesqlqueriesfor(I)To(Vii)Onthebasisoftableitemsandtraders:
[S]
Table:ITEMS
Page15
L -------------------------------
r -------------------------------,
vii. Obtaintheoutputsofthefollowingsqlqueriesbasedonthedatagivenintablesitem
sandtradersabove.
a. SELECTMAX(PRICE),MIN(PRICE)FROMITEMS;
b. SELECTPRICE*QTYFROMITEMSWHERECODE=1004;
c. SELECTDISTINCTTCODEFROMITEMS;
d. SELECTINAME,TNAMEFROMITEMSI,Traderstwherel.TCODE=T.TCOD
EANDQTY<Loo;
OR
Considerthefollowingtablesworkerandpaylevelandanswer(A)And(B)Partsofthisqu
estion:
Table:WORKER
i. Todisplaythenameofallworkersindescendingorderofdob.
ii. Todisplaynameanddesignofthoseworkers,Whose
Pleveliseitherpoolorp002.
Page16
L -------------------------------
R-------------------------------,
iii. Todisplaythecontentofalltheworkerstable,Whosedobisinbetween'19-
JAN-1984'and'18-JAN-1987'.
iv. Toaddanewrowwiththefollowing:19,'Dayakishore','Operator','P003','1
9-Sep-2008', 17-Jul-1984'
b. Givetheoutputofthefollowingsqlqueries:
i. SELECTCOUNT(PLEVEL),PLEVELFROMWORKERGROUP
BYPLEVEL;Ii.SELECTMAX(DOB),MIN(DOJ)FROMWORKER;
iii. Selectname,PAYFROMWORKERW,PAYLEVELPWHEREW.PLEVEL=P.
PLEVELANDW.ECODE<13;
iv. SELECTPLEVEL,PAY+ALLOWANCEFROMPAYLEVELWHEREPLEVEL="P003
1
1
;
[4]Andaccessories.
TABLE:SHOPPE
Id Sname Area
Sool Abccomputeronics CP
S002 Alllnfotechmedia Gkll
S003 Techshoppe CP
S004 Geekstecnosoft Nehruplace
SOOS Hitechtechstore Nehruplace
TABLE:ACCESSORIES
No Name Price Id
Aol Motherboard 12000 Sol
A02 Harddisk 5000 Sol
L ------------------------------- Page1O
r -------------------------------,
(Ii) OR
I. Givethesyntaxofdropstatement. [1
]
Ii. Considerthefollowingtablestore.Writesqlcommandsforthefollowingst [4]
atements.
Table:STORE
Page12
L -------------------------------
r -------------------------------,
ii. Todisplayitemnoanditemnameofthoseitemsfromstoretablewhose
rateismorethan15rupees.
iii. Todisplaythedetailsofthoseitemswhosesupplierscode(Scode)Is
22orquantityinstore(Qty)Ismorethan110fromthetablestore.
iv. Todisplaytheminimumrateofitemsforeachsupplierindividually
asperscodefromthetablestore.
Sectione
34. Writeaprogramtoperformbinarysearchonalistofstringsarrangedindescending [4]
Order.
b. SELECT*FROMEMPLOYEEWHEREAGE>34ORDERBYNAME;
c. SELECTNAMEFROMEMPLOYEEWHEREAGE>34;
d. SELECTNAMEFROMEMPLOYEEAGE>34ORDERBYNAME;
Page13
L -------------------------------
R-------------------------------,
ii. Writeaquerytodisplayareport,Listingname,BASIC,Departmentandannualsa
lary.Annualsalaryequalstobasic*12.
iii. Insertthefollowingdataintheemployeetable
11,'VIJAY',9300,'FINANCE','13/7/98',35
,"M"
iv. Writeaquerytocountthenumberofemployees,Whoareeitherworkinginpe
rsonnelorcomputerdepartment.
v. Writethedegreeandcardinalityofthetableemployee.
L ------------------------------- Page13
r -------------------------------,
Solutions
Sectiona
1.
(B)False
Explanation:False
Thelistsareordered.
2. (A)Likeoperator
Explanation:Likeoperatorisusedinthewhereclauseallowsusasearchbasedoperationonapat
tern.
3. (A) S._Getitem_(I)
Explanation:Itisthecorrectsyntaxtocallcharacteratindexiofstrings
4.
(C)50#5
Explanation:50#5
5.(A)Analogsignal
Explanation:Ananalogsignalisany Continuoussignalforwhichthetime-
Varyingfeatureofthesignalisarepresentationofsomeothertime-
Varyingquantity,I.E.,Analogoustoanothertime-
Varyingsignal.Analogsignalsproducetoomuch
Noise. Examples:-Humanvoice,Thermometer,Analogphones,Etc.
6.
(C)Infi.Readline()
Explanation:Readline()Functionreadsalinefromthefilepointerposition.
7.(A)Localhost
Explanation: Localhost
8.
(B)DDL(Datadefinitionlanguage)
Explanation:DDL(Datadefinitionlanguage)Isthelanguagewhichperformsalltheoperation
indefiningstructureofrelation.
9.
(B)Read()
Explanation:Read()Functionreadsthewholefileandreturnsthe Textasastring.
10.(A)None
L -------------------------------
r -------------------------------,
Explanation:None
11.
(C)1
Explanation:1
12.
(B)Functionsarereusablepiecesofprograms
Explanation:Functionsarereusablepiecesof Programs.Theyallowyoutogiveaname
Page14
L -------------------------------
r -------------------------------,
Toablockofstatements,Allowingyoutorunthatblockusingthespecifiednameanywhereinyou
rprogramandanynumberoftimes.
13.(A)True
Explanation:True
14.
(B)Typeconversion
Explanation:Typeconversion
15.1.LIKE
16.
(D)Codedivisionmultipleaccess
Explanation:Cdmastandsforcodedivisionmultipleaccess.Inthis,Eachuserisallocatedauni
quecodesequence,Thatisusedtoencode/Decodetheoriginaldata.
17.(A)Bothaandraretrueandristhecorrectexplanationofa.
Explanation:Theintersection_Update()Methodisdifferentfromtheintersection()Method
since Itmodifiestheoriginalsetbyremovingthe
Unwanteditems,Ontheotherhand,Theintersection()Methodreturnsanewset
Removingtheunwanteditems.
18.
(B)Bothaandraretruebutrisnotthecorrectexplanationofa.
Explanation:Csvstandsfor"Comma-
Separatedvalues",Whichisdefinedasasimplefileformatthatusesspecificstructuringtoarran
getabulardata.Itstorestabulardatasuchas
Spreadsheetsordatabasesinplaintextandhasacommonformatfordata
Interchange.Inpython,Thecsvmoduleisusedtohandlethecsvfilestoread/
Writeandgetdatafromspecifiedcolumns.
Section B
19. Answer:
(i) I.Theprocessofalteringthecharacteristics(Amplitudeorfrequencyetc.)Ofahigh-
Frequencywavecalledthecarrierwavesothatitcancarrylow-
Frequencyinformationalongwithitwhilebeingtransmitted,Iscalledmodulation.
Ii.2Gnetworksprimarilyinvolvethetransmissionofvoiceinformationwhile3Gtechn
ologyprovidestheadditionaladvantageofdatatransfer.
(ii) OR
i. Therearemanymethodsofcheckingordetectingerrorsinthedatatransmitted.Thef
oursimplestonesare:
i. Singledimensionalparitychecking
ii. Two-Dimensional Paritychecking
Page15
L -------------------------------
r -------------------------------,
iii. Checksum
iv. Cyclicredundancycheck(CRC)
20. Importmysqldb
Db=Mysqldb.Connect("Localhost", )
"Admin","Ad123",11HMD11cursor=Db.Cursor()
Page16
L -------------------------------
r -------------------------------,
Cursor.Execute("Droptableifexistslocation")
Sql="11 "Createtablelocation(Idnumeric(S)PRIMARYKEY,Bidycodevarchar(Lo)
Notnull,
Roomvarchar(G)Notnull,Capacitynumeric(S)Notnull)"11 11
Cursor.Execute(Sql)Db.Cl
ose()
21. To=30#Variablenameshouldbeonlhsforki
nrange(O,To)_;_#:Wasmissing
Ifk%4==0:#Ifshouldbein Lowercase;I.E;If
Print(K*4)
Else:#Else
Shouldbeinlowercaseprint(K+3)
OR
Theabovecodewillgiveerrorbecausekeywordtruehasbeenusedasvariable(Infirstlineofc
odetrue=False).Wecannotusekeywordsasvariablesoranyotheridentifiers.
22. Answer:
(i) Importmysql.Connector
Asidentifier_Namee.G.
Importmysql.Connectorasmydb
(ii) Itwilladdanewrecordinthedatabaseafterobtainingvaluesofperson-Id,And
Lastnamefromuser.
23. Differencesbetweenlogicalerrorandsyntaxerrorareasfollows:
Logicalerror Syntaxerror
Itoccurswhenstatementsarewrongly
Itoccursbecauseofwrongimplementation writtenviolatingrules
Oflogic. Oftheprogramminglanguage.
Withlogicalerrors,Thecodeissyntacticallyc Withsyntaxerrors,Thecodeisnotsyntac
orrectandcompilerwillnotshowanyerrormes ticallycorrectandcompilerwillshowthe
sage. errormessages.
Itproducestheoutput,Butundesired. Itdoesnotproduceanyoutput.
E.G.Inplaceof(C=A*B);Ifbymistake(C=A E.G.Inplaceof(A==B);Ifbymistake(A==
+B);Iswritten,Itwillbealogicalerror. B);Iswritten,Itwillbeasyntaxerror.
OR
Inthegivencode,Aisaninttypevariable,Whichisanimmutabletype,Whichmeansitsvalu
Page17
L -------------------------------
r -------------------------------,
ecannotchangeinplace(I.E.,Inthesamememorylocation).So,Whenthesecondstatement
getsexecuted,Thevariable
Nolongerpointstothesamememoryasitwasinstatement1.Sointernallyitismadetopointto
a Newlocationwhichstoresitsvalue
24. So,Inawayanewaiscreatedafterstatement2.
Page18
L -------------------------------
r -------------------------------,
Thus,Whenwemakechangesinanimmutabletypevariable,Internallypythoncreatesane
wvariablehavingthenewvalueandhencenoerrorisreported.Changeofthevaluedoesnott
akeplaceinthesamememorylocationforanimmutabletype.
24. Defreadfile():
I=Open("Employee.Dat",
"Rb+")X=I.Readline()
While(X):L=X.Sp
lit(':')
If (20000>=Float(1[2])<=40000}:
Print(X)X=I.Readl
ine()
OR
Fileobject=Open("An.Txt","R
")Forlineinfileobject:
Words=Line.Spli
t()Forwordinwor
ds:Forcharinwor
d:
If(Char.Isdigit()):Print(C
har)
25. Defget_Ones_Digit(Num):#Returntheonesdigitoftheintegernumo
nes_Digit=Num%10
Returnones_Digit
Get_Ones_Digitfunctionreturnsthedigitatone'spositionofnumbernum.
Sectionc
26. Answer:
(i) I=[]
Foriinrange(200,300}:If(I
%7==0}And(I%5!=0}
I.Append(Str(I)
)Print(','.Join(I))
(ii) Output
{'D':4,'A':1,'C':3,'B':2}
Page17
L -------------------------------
r -------------------------------,
{'D':4,'C':3,'B':2}
27. Defprime(N):
Fornuminrange(2,N):Is
_Prime=1
Foriinrange(2,Num):
Page18
L -------------------------------
r -------------------------------,
Ifnum
%I==0:Is_Prime=0
Ifis_Prime==1:Pri
nt(Num)
28. I.SELECTP_Namemax(SAL)
Fromprogrammers;
i. Updateprogrammerssetsal=SAL+2000WHEREP_Name LIKE R%
1 1 ;
OR
Indbms,Thisroworrecordisknownasatuple.Henceindbms,Atupleisjustarowrepresentings
omeassociateddataforacertainentity,Suchasauser,Student,Oremployee.Youcanseefromth
efigureabovethatatupleisarow
Ofinformationaboutasingleitem,Suchasitsname,Age,Marks,Etc.
29.Userdefinefunctiontodisplaytotalnumberofwordsinafile:
Defcountwords():
S=Open(11Quotes.Tx 1r 1
,
)
t11
F=S,Read(
)
Z=F.Split(
)Count=O
Foriinz:Count
=Count+L
Print( 11Totalnumberofwords",Count)
30. Defbinary_Search(Sorted_List,
Number):Low=O
High=Len(Sorted_List)F
ound=False
While(Low<High)Andfound=False:
Mid=Int(Low+High/2)
Ifsorted_List[Mid]==Numbe
r:Print
("Numberfoundat 11,Mid)Fo
und=True
Break
Elifsorted_List[Mid]==Number:
Page19
L -------------------------------
r -------------------------------,
Low=Mid+1
Else:
High=Mid-
1iflow>=Hig
h:
Print("Numbernotfound")
Max_Range=Input(11entercountofnumbers:")Numlis
t=[]
Foriinrange(O,Max_Range):
Numlist_Append(Input(11Enternumber:11
}}
Page20
L -------------------------------
r -------------------------------,
Numlist.Sort()P
Numlist)
rint(110urlist:1
,
Number=Input(11Enterthenumber11
)
Binary_Search(Numlist, Number)
Section D
31. I.Administrativeofficeisthemostsuitablelocationforthemainserverofthisinsti
tutiontogetefficientconnectivity.
ii. Switchtobeinstalledineachofthesebuildingforconnectingcomputersinstalledwithint
he Building
iii. Topology:Startopology
Networkcableethernetcable/Coaxialcable
32. I.SELECT*FROMITEMSORDERBYINAMEASC;
ii. SELECTINAME,PRICEFROMITEMSWHERE PRICE=>10000ANDPRICE=<22000;
iii. SELECTTCODE, COUNT(CODE)FROM ITEMSGROUPBYTCODE;
iv. SELECTPRICE,INAME,QTYFROMITEMSWHEREQTY>150;
11delhl1
v. SELECTTNAMEFROMTRADERSWHERE(CITY= OR(CITY=11mumbal11
)
1
)
Ii.SELECTNAME,DESIGNFROMWORKERWHEREPLEVEL=11pool11 ORPLEVEL=
Page21
L -------------------------------
r -------------------------------,
11Poo211
;OR
SELECTNAME,DESIGNFROMWORKERWHEREPLEVELIN('Pool','P002');
Page22
L -------------------------------
r -------------------------------,
ore 11 11 11
20081,17-Jul-1984');
2 P002
2 P003
Max(DOB) Min(DOJ)
12-Jul-1987 13-Sep-2004
Name Pay
Ii.
RadheShyam 26000
ChanderNath 12000
PleveI Pay
Iii.
P003 18000
Iv.
33.Answer:
(i) I.Thewhereclause Isusedtoextractonlythoserecordsthatfulfila
Specifiedcriteria.
ii. I.Selectname,Pricefro
Page20
L -------------------------------
r -------------------------------,
maccessoriesorderby
price;
ii. Selectid,Snamefr
omshoppe
Wherearea='Nehruplace';
iii. SELECTMIN(Price)"Minimumprice",MAX(Price)"Maximumprice",Na
mefromaccessories
Groupbyname;
Page20
L -------------------------------
r -------------------------------,
iv. Selectname,Price,Snamefromacce
ssoriesa,SHOPPESWHEREA.Id=
S.Ld;
Butthisqueryenabletoshowtheresultbecausea.Idands.Ldarenotidentical.
v. Selectnamefromaccessorieswhere
price>Looo;
(ii) OR
i. Droptabletable_Name;
ii. I.SELECT*
FROMSTORE
Orderbylastbuy;
ii. Selectltemno,Itemfro
mstore
Whererate>15;
iii. SELECT*FR
OMSTORE
Wherescode=22orqty >110;
iv. Selectscode,Min(Rate)F
ROMSTORE
Groupbyscode;
r:Beg=Mid+L
Else:Last=Mid-1else:
34. Defbsearch(Strarr,St
Returnfalse
r):Beg=O
Last=Len(Strar ---Main---
r)-
1while(Beg<=L
ast):Mid=(Beg
+Last)/2
Ifstrarr[Mid]==Str:
Returnmid
Elifstrarr[Mid]>=St
Page21
L -------------------------------
r -------------------------------,
Sectione
N=Int(Raw_Input("Enter
No.Ofelementsofthearray".)Print(''\
Nenterstringsindescendingorder:")
Ar=[""]*N
Page21
L -------------------------------
R-------------------------------,
Foriinrange(N):
Ar[I]Raw_Input("String"+I+":")
Item=Raw_Input("Enterstringtobesearched:")F
oundat=Bsearch(Ar,Item)
Iffoundat:
Print''\
Nelementfoundat",Foundatelse:
Print11\Nstringnetfount"
35. I.(A)SELECTNAMEFROMEMPLOYEEWHEREAGE>34ORDERBYNAME;
ii. SELECTNAME,BASIC,DEPARTMENT,BASIC*12"Annualsalary"FROMEMPLOYEE;
INSERTINTOEMPLOYEEVALUES{L,'VIJAY',9300,'FINANCE','13/7
iii.
/98',35,'M');Iv.SELECTCOUNT(*)FROMEMPLOYEE
WHERE DEPARTMENT='PERSONNEL' OR DEPARTMENT='COMPUTER';
V.Degreeofthegiventableis7 Andcardinalityis10.
L ------------------------------- Page22