23 Python External Paper 2020-21 ODD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

l'l'Jntea rage:

n!I!~
J 01 4
8
111111111 llll l/~!!l,11111111111111111111 r--~r--r--r--,---,--,"_b~jec1 Code: KN C302

"" 101 2
Roll No: ..._._~.J..:::......J...::::~:__L_..LL.._._--..._

r£CH
~-E~INATION 2020-21
(SEM Ill) THEOR~ROGRAMMING
Time: 31 Hours PYTHON . . Tota/ "A6•rks: JOO
Note: . Att en1{)t nil Sections. If require
. any niissmg data; then choose suitably . 1

SECTION A
I. Atte nip1 alt questions in brier.
\ Q no \ , Question
11
t---
\ a. ~:;:;.:-~~
\ What is the use ~C.=~;;::;~:=::~-:-:;--
of" raise" statement? Describe with an - - - - ~M,arks CO
example
2 5

l
ib. \ Write a recursive Python function "rprint" to print all elements in, 2
hst m reverse. 3
rprint([ )) prints nothing
rpri nt( [l,2,3]) prints 3 2 1
l
k
c. - 1 - - - - -- - - - -
Describethebehaviorof"range (s,- - - - - --+;--11
e )"inPython. 2 3-
d.
k -l - -- - - - - - - - - ~ - ~- ~2 -Tss-
Explain the use of "with" construct in Python with an example
program. . r()Oj ., ~)
I e. --L ___________i=~V~ ~~-;;----f-;)11- \I",
1 , .,,
t--
Which of the following statemen~ produc~ error in Python?
2
x, y , z" 1,2,3 Isl -) '~
a, b "4,5,6 I s2 _ /'i,/ AA
u "7,B,9ls3 ~ _ \\
f. (List ail tho statomonts that have ~Mr'.l , I'.,•
Explain tho rolo nf p,oeOO,nc~ itH an exampt,. <::)
g. (\., l\ .
d
Bow do you rea an m~ . ' 1rom a user in Python to be use d as an rn!eger
·, 2 5
.<,;;°J
c:
in tho rnst nf tho program? Explain With an example.
h. Consider the program:
.
2
x
x[QJ
= ['12',
*= 3
'hello', 456] "-
·,
":'}
x [1][1] " 'bye' (1,,,1'._
. program generates an err?r:
Explain why this .-C',
'L,' '
l.
What is the output of the followipg program? 2 5 I
I
,, r"i.,...,
{
(lambd x,y : Y - 2'''?<) ' U, ll)

J. Explain the use of· '


1 t "function in a class Python? 2 5
I I
!
Ill IIIII IIIII I1111111-~111111111111111111 II Ill
APf:~1D-311 012

2. Atteh. SECl'I ON H
,. . .0- 11 0-. -r----_:•Pt any tlrree of the followin g:
Mark s CO
a. w rite . Question .
stri11 a Pyth0n funct ion remove kth ( s , k ) that takes as mput a I 0 5
8
is be! aotl an integer k>==O and removes the character at index k. If k
0nd
fue length of s, the whole of s is returned. For example,
t' emov-ekth"
r~mo •· ( PY THON "
"' ve k t h 1 ) returns " PTHON "
rem (" PY THON", 3)
o ve Xth ("P YTHON',' returns " PY TON"
removel{th ("PYTHON", 0 ) returns " YT HON "
I----+--.- - - ' 20) returns " P YTHON"
b. Wnte a PYthon fu . __ . ------=----------:+--:-:::---T:;-7
numbers . 1'he fi nction. av er age to compute the average of a list of l o 3
unction must h
where th e input . . use tr y-e xcept to andle the case
. 11st 1s empty F .
empty l1st should be s · Urther, m that case the average for the
f' et to 0.0 using the except block.
Describe the diffffi;:;:=:::-::.:--:- - = - - - - - - - - - - -----+----+-:--1
erences between a li_near search and a binary search? 10 5
d. 1 ::_--:-:-;--:-:-- -------==----------l--+~
Write a functio~n;,--
than k from l' es s th an (1st, k) to ret!!!®l-ist of numbers less l 0 4
1st 1st
Example: a - The function mus~ Yist comprehension.
lessthan([l
' - 2 , 0 , 5 , - 3 ]( returns [ - 2 , - 3 ]
-(.• ),1 . .. . .
e. . Write a program fa t
0
fN (N =l) F c ors (N) tl}at•?e.tumsahstofallpos1t1ved1v1sors
> · or example: V \
J.e!\ 2
factors (6) returns [} ~3161 ( 1"'•
factors(l) retums .. ( lJ , · ~\) '"'
factors (13) retumK°r [l 13] ', '·
Y"' , ,,..,. .

SECTIONC
3
Qno.
Attempt any one part of the following :
Question
.
,,v
'~. Marks co
a.
'l'»
How can you create Python file that can be iiµt tted as a library as well
as run as a standalone script?
10 5

b. Describe the difference between • § ' 10 s


i mport library ~/
and
II \
·
,
fr} ~ , J \\
from library ~~.Gfrt * .
when used in a python'Qrogram. Here library is some python
librarv . '\.

l
1111 SubJect -
'"" I H!'l'!l,1~11111111111111111111111
1 1012 Roll N °: D--r1-•1---r1-r-1--r1- r-1_:_:I _ .J -l_L J___LJ
4. Atternpt a part of the following:
l\y one
Qno. Questioll r--
Marks co
a. Write a fu . k Pairs that takes as input two lists of equal r---
nctton ma e h 10 2
le~gth and returns a single list of sarn~ 1engt where k-th element is the
pair of k-th elements from the input 1tsts. For example,

make Pai r s ( [ 1 , 3, s, 7 ] , [ 2 , 4 , 6' 8 ] )


returns [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6) , ( 7, 8 ) ]
make Pai r ~ ( [ ] , [ ] )
returns[]
I

j
b. Show an example where both Keyword arguments and
Default 10
arguments are used for the same function in a call. Show both the
definition of the function and its call. \ 4

5 Attempt any one part of the following:


Marks CO
Qno. Question ,. . . ...,,
1O 1
a. Explain why Python is considered an interpreie~ Language. (') ...
L_J _ - - ----:---:--------:---.----;::-;~~-~t.6/"'-'
~ ~ ~ ~- \lO~i;:-1
What is short circuit evaluation? What j s~ nied by the following
1
O •
=:
b.
Python program? QV '\ '

L~I:~
Cj.., 1\ \

"-~t \
a =.: O \

a S-'0 /
y- <;
h
..I
Ill IIIII I llli ~11 IIlllllllllll
11111
tR ID-311012
11111111111111 Suh_jcct Cod(': l(~Ufp

6. Ro11 No: - ~-
I L__ u-1-~ '..J
Att~ I

tnpt any o11e part of tl1 e folIow1·no·


_______ ~·
Marks CO
W• . Question -----:-- - .--:- ---:.--+---t--~
hati_ . 1e (N) , that prints a nght .h·1angle IO
te abPython program , t r1ang
vln 3
'=:.talnples:
g ase and height cons·isling
..; of N .- symbols as shown in these
l:t .i_i:l. ·,
'It ng le ( 3 l Prints:
**

triang1
* e (5) Prints:
**
** *
****

b. Write a P"th
J' on program
of perfect squares 1ess than
' countsquares (N), that returns the count 10 4
countsquares ( 1 or equaJ to N (N> l).,Ror example:
) r eturns 1
# Onl y 1 · "-
°';vJ
countsquares ( 5 ) is a )'J-0 ect square <= 1
re t \J.rns 2
# 1, 4 <'t r e l'R'~ f
countSquares (5S) retur\~e,-- ect squares <= 5
- - . # l ' 4 - (g'\;, 1 6 ') 5 ..,
' ' ,... , ,._ , ,) 6, 4 9 <= :5'S - -
7. 'J ,
Attempt any one part~ fo:owing: ~)
\-,;.;;-.--~~=-------~'~ --r-:-~~
Qno.
a. _l Question (')... '\. Marks CO
Write a Python function, alternating (1st), tqt t~•takes as 10
~rgument a sequence 1st. The function returns Tr~e 'ft,the elements 4
in 1st are alternately odd and even, $tarting with·ah"even number.
Otherwise it returns False. For example: >\\)( ·
alternating ( (10, 9, 9, 6]) returtIB"{'alse
alternating ( (10, 15, 8]) retu~ t,rue
alternating ( [ 10]) returns Tru~ '\J
alternating ( []) returns True~ .
alternating ( [15, 10, j \,0 eturns False

b.
n~ ~-
Write a Python function, tst '.!rchMany(s, x, k), that takes as 10
argument a sequence s lili{ integers x, k ( k> 0) . The_function returns 3
True if there are at most k occurrences of x ins. Otherwise it returns
False. For example:
searchMany ( [ 10, 17, 15, 12], 15., l)returnsTrue
searchMany ( [10, 12, 12, 12], 12, 2) returns False
searchMany ( [ 10, 12 , 15 , 11 ] , 1 7 , 18 ) returns True

You might also like