0% found this document useful (0 votes)
7 views15 pages

dsp QB

The document is a class test for a DSP course, containing various questions related to Python programming concepts such as dictionaries, sets, lists, and tuples. It includes tasks to write Python programs, describe methods and operators, and explain data structures and functions. The questions cover a range of topics from basic syntax to built-in functions and data manipulation techniques.

Uploaded by

priyankasakpal72
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)
7 views15 pages

dsp QB

The document is a class test for a DSP course, containing various questions related to Python programming concepts such as dictionaries, sets, lists, and tuples. It includes tasks to write Python programs, describe methods and operators, and explain data structures and functions. The questions cover a range of topics from basic syntax to built-in functions and data manipulation techniques.

Uploaded by

priyankasakpal72
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/ 15

AN

DSP Class Test1 QB


L List any two ifferences between dictionary and set
2. Write a python program to display helo text.
3 Write python program to perform following list operation

2.4]-YI
S2>printit)
4. Deseritbe any three methods of lists in python
S. Write a program to create dictionary in python
6 Describe tuple in python and write syntas to create tuple.
7. Write a python program to create list for 5 items in python.
$ Write the output for tolowingif the variabie fruitemango using list
>fruit-21
>>>ruit(11
3frult[13)
sfruit:l
9. ist ary two features of python
10, Define set in python with exampie
11. Explain merge of two dictionaries
12. Describe membership operators in python.(in, not in)
13 Describe any two data conversion function.
14. Describe keyword continue with example
15. Describe creating dictionary and accessing dictionary element wth esample
16. Explain any four python builtn function with example.
17. Explain bitwise operator in python with example
18. Write a python program to calculate sum of digit of gven number using function.
19. Writea python program to find the largest number and smallest number in a list
20. Explain ay three set function with eample.
ALFAH Page No.
DSP QB Date:

an) andset
ist beteen

DA
Dichonag
Dict iongxy censistA sed is
Set
a cellection et
of a coll etion of unorlere tems means
Lobiects as Bey not in any particulay
yalepairs. Lordex:
2A The elementsinThe elemente n Set are
im muta ble meanS cannat
mutable means chang eab be changec
|le

Qzile a python pzoqana


pragana ta
to displa
isplay hello" tex
Lerint (Hello.") alp Hello

aMDescibeat
>]apptndnsatfl
mase
three methods af lieh 'n athon
removeC
Vxevase
as)lte a pragam 4o create distionay jn athar
Imy d=t|lo 2:2o314, s,l 4ibye hyef
prink C" accesstem" my dLs)

Shot on OnePlus
Powered by Triple Camera 2023.09.01 12:18
Date:

Cox

python and
andl wnte
wnte syndaxta
Q6Desciibe. tuple in
Ceate Luple
kre
usel to
’)aples is the dat a type in RtAon
storemdiple data i t s na sinqle Variable
alos
ahich is ordexe cl Un- change able and
plicate values
benmbers 0Y
iJlData itens n tuplesmay be nu
sting qnd must b
be enclosccl within g0n d
brackets C) separate by Comqc

Taples cannot be updated that's why


uples celle READ ONLY Lit

i)Syatax i- te=(L2c,2,3). hella")


-pxint (" tuple", te) ajie taple (i,2,ea
hello)
Qite a eython pnoam to czete list foy

’ Paxin xange(s)i
Lem input CE"entey item Ci+1)
jtem Aseppenc Citem)
Loont C The lst ef Temstemi)
be'm
print( i )
for x in li
print (x)
Shot on OnePluS
Powered by Triple Camera 2023.09.01 12:19 b
ALFAH| Page No.
Date:

)ist ang
any to feattr of python
icasy to Cocle
Fee anc apeo So
nCasy to Reacl
Qlo Define set a pqthon with example 24

’ i h mathematicsacet is a callectin ot
anorereitems means no t ' n any paxdicula
oT@ey.
simlar to this
pathen Set S heqy about
mathe matical denition

the elementso the set annat be duelicaes


Tbe elementsn the set are immteble means
cannot be mod)fee oY chang ecl bLt the set q
a wwhole motab leu

J¥La pythao Set D0 index attachel is to


elemen hen ce set do na t suppoYt 9n4
lany sliciag operation
indecing

Shot on OnePlus.
Powered by Triple Camera 2023.09.01 12:19
YDesaibe mem besship opesctos in python nDst
yThe membexsbipopeiatos in pthon ased to
test whethey aVelueox Variable fhunc in a
stingeist, tuplesed and dicthinnay
YouCan
notthe
Qnly test foy pfesence ot
Valee in a dctiona
3 ) f the vale is pncseot ia the ata atrctse
sych qs
shiaqRist tple, set ancd dicionsry
thenyetns tue othe
tiueothey sexetrns false
4 -The hembeiship
nembeiship opesatoxS are gien belo
boi- xetyrhtaet a se quence th specha
Val ue s p i esent inthe object
l'not in ; - geturn txuef aSequence with.
he specified velye snot pre sent
)nthe obect

Qescoibe any two conyasion function:


’1 int Cx)- Usec to conkt to an inteqe
Base specifics the base )f
a s
ing
Ex a mple int C'20 22")
olp = 2022

Shot on OnePlus
era 2023.09.01 12:19
ALFAH Page No.
Date:

float):- Vsec to conert c t o a


point numhhex
example i floet ( 2 )
£lasting
Olp 2
a2hite a Pythanpraqram
python to sperform folin
List aperato n

S>>nt Ct)

QDescibe three methods otlists n


any
Python

gikn lata tem eY elem ent to ths


list at the gieo indea
example i - 2i a p r ' , o b' e' 'm'
einset C2, 's)
prot( new list i

2)pop():-The pop) unckian isele to


element at specified
ndex fom the is andd setns
the papec ele ment

Shot on OnePluS
OnePlus on
Shot
Liae) (seserse print
place istin the
idemof lQeta element
']
e', m lasti pop
= lp
i) Aist:" ("pap print
Date:
Date:

Qozite the outout or falloLjng the yaåable


mangusinqhst
aied)itCI:

ange
mango'
Me

a) Qescibe a Keysorcl centinue ith ex ample


DlContinue state hoeeat s a loo conbol statercont
lasalhat tces al
forces to exe cke the ext Leraton of the
lo op hile ckipping the ses t of the cacle

Eox example i- fas) in zanqe (a)i


continLe
print (i)

Shot on OnePluS
Powered by Triple Camera 2023.09.01 12:19
dictien9asy ancl gcesSinq
sDesciba creating
elemeot with xqnple
'evel

cdionaydic ti onyiTt involves sLocihg paixs ot ble


plica

>lCinting
values They ax
eys and theiy conponing
ntten with curly bracetso
lanclcolen: to Qelne Lhe ey Values.
pais withun the lictionon

print dict :" myd}

elemeats i- Access)ng
Accessing dhctionag
in pthon in voles hchopant ebmeals
inq thekeds of the
cioaaxy to vetieve theiy asssociateal values
You ca 25e sauare brgcke bs anc pzoxiclin
4he elesireel key
key within them
exi- my
pint
pi nt acess 3iemi?m y d o
olp =dicl :fi:lo 2:20, 3: 5.s,61
bycbye
qccesS 3te m:
bye bye

Shot on OnePlus
Powered by Triple Camera 2023.09.01 12:19
ALFAH Page No.
Date:

l6Eaplain any fo pdho.n


Pylhon bujlt in fncton
(xgmple
slicatior
Retuns Smallest valye among
oTgumcats Suppied ibles

DML

abs () : ;e fc

Absolte function also Rnown


Rac as molulu sto
retenS the n-heqae
ahRgaikt Vale of the tab

angument value ej

C-s)

Converts an objectto a sting Yepese ntesh

Retns he ot
leagth a
shing
Ex;len CHella'

Shot on OnePlus
Powered byTriple Camera 2023.09.01 12:20
(ALFAHP
Date:

Pow C):The pow)Aunction xetns the


value of to the powt, o y
athir pcnameter Js p seht i
7etuns to the po oty-

Qr explain biteise o0erato n pythan bith


example
Bitise operato ae secl to manip4late
iadividualan bits of iategcs
Operan the bin ay epeseotti on ot
the numbey The m btise aperabor
Q c BitlwiseAND operator)i
Ths Opesation pestoxms AND pexaho n betweem
opeiands operatoY Copies a bit to the Rsut
in boAh operane

^Gduise XOR opegtoy


copies the bit it is sed '
operanl but not both.

Dperatoy:
-Thisportn bit 1L exists in ithe
Lopaenc
Shot on OnePlus
Powered by Triple Camera 2023.09.01 12:20
ALFAH Page No.
Date:

D<<(bitLise
Tie
lft sbi£tapera toz)
let op ¬xand s moveellef4
by he nmbex bits oW
specitiol by the
iaht operano n

CBitse
>>(Bitise ahtShlft
shit operator) The Se

Qperancl
Lhumbty ot bits pecied by the ~ight
perand

pzint ( ae b
print afb alb)
pint a b
printa << 2
PriotCas2
2
3
a7b

Shot on OnePlus
Powered by Triple Camera 2023.09.01 12:20
2023.09.0112-20 Camera Triple Powered
by
OnePlus on
Shot
Smallest laznest, rttunm
num Smallest
s
Smallest: <nurn it
Aangest
numhes in num for
Numhes
[o Smallest= 1orgest
None None, rturn
numbersi not if
(numhecs): Smallest largest
- find- def
List
in
hymber est Small and bey nect tt larq
toind
the pzogram python a te Q14
xesut) digits: otsm intC
")) n4mber ("Entr intCinpt num
S4m toal Yetuy
humba=la
numberlo
lo cligit
=
achile
totalS.
ber)i Gn4m digits cletsm
sing d'git
VsL numb
pythospongra lilea
sum calcalat do
Date:

poqram to find the laroest numnbco


QndSmallesk numbe in lis.

numberlist E1245623956 3418


laqestSmalles 5 findlaraest- andsmallest
Cnumbec-list ) e

print Laest numbec i laces) er

pnint SmaMest num hesi Smallest )


olp
Smalles numbex: G

Q2aFxplain
Explain Ons thxee Sek functian with example.
all)
Retunm Tnue f all elements of the
Fne tme (Or if the set is empty)
Ex

Shot on OnePlus
Powered by Triple Camera 2023.09.0112:20
others.
Built-in functions likeall). any),
used with set to perform different enumerate(), len), max), min (0, sorted), sum) etc. are commonly
tasks. Consider set A= (3, 1, 6, 7}.
" Following table lists built-in functions for set:
ST.
Punction Description
NO.
1
Example
all() Return True if all elements of the set are true (or if the set>>> al11 (A) True
is empty).
2. any() Return True if any element of the set is true. If the set is>>> any (A) True
empty, return False.
3. len() Return the length (the number of items) in the set. >>> len (A)
4
4. max() Return the largest item in the set. >>> max(A)
7
5. min() Return the smallest item in the set.
>>> min (A)
6. 1
sorted() Return a new sorted list from elements in the
sort the set itself). set(does not >>> sorted (A)
7. sum() Retrun the sum of all elements in the set. [1, 3, 6, 7]
>>> sum(A)
17

You might also like