Python Programming KNC 302-1-2020
Python Programming KNC 302-1-2020
SECTION A
1. Attempt all questions in brief.
Q no. Question Marks CO
a. What is the use of “raise” statement? Describe with an example. 2 5
P
program.
0Q
1
13
e. Which of the following statements produce an error in Python? 2 1
29
x, y, z = 1,2,3 # s1
2.
0E
a, b = 4,5,6 # s2
24
P2
u = 7,8,9 # s3
5.
(List all the statements that have error.)
_Q
.5
f. Explain the role of precedence with an example. 17 2 1
TU
6
:5
x[0] *= 3
x[1][1] = 'bye'
1
02
AKTU_QP20E290QP | 12-Mar-2021
Downloaded 14:07:56 | 117.55.242.131
from : uptukhabar.net
Printed Page: 2 of 4
Subject Code: KNC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
SECTION B
2. Attempt any three of the following:
Q no. Question Marks CO
a. Write a Python function removekth(s, k) that takes as input a 10 5
string s and an integer k>=0 and removes the character at index k. If k
is beyond the length of s, the whole of s is returned. For example,
P
d. Write a function lessthan(lst, k) to return list of numbers less 10
0Q 4
than k from a list lst. The function must use list comprehension.
1
13
Example:
29
2.
0E
24
e. Write a program factors(N) that returns a list of all positive divisors 10 2
P2
5.
of N (N>=1). For example:
_Q
.5
factors(6) returns [1,2,3,6] 17
factors(1) returns [1]
TU
6
:5
SECTION C
07
a. How can you create Python file that can be imported as a library as well 10 5
1
import library
and
M
2-
library.
Downloaded
AKTU_QP20E290QP from : uptukhabar.net
| 12-Mar-2021 14:07:56 | 117.55.242.131
Printed Page: 3 of 4
Subject Code: KNC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
4. Attempt any one part of the following:
Q no. Question Marks CO
a. Write a function makePairs that takes as input two lists of equal 10 2
length and returns a single list of same length where k-th element is the
pair of k-th elements from the input lists. For example,
makePairs([1,3,5,7],[2,4,6,8])
returns [(1,2),(3,4),(5,6),(7,8)]
makePairs([],[])
returns []
P
Q no. Question 0Q Marks CO
a. Explain why Python is considered an interpreted language. 10 1
1
13
29
2.
0E
Python program?
24
a = 0
P2
5.
b = 2
_Q
.5
c = 3 17
x = c or a
TU
print(x)
|1
AK
6
:5
:07
14
1
02
-2
ar
M
2-
|1
triangle(3) prints:
*
**
***
triangle(5) prints:
*
**
***
****
*****
P
countSquares(1) returns 1
0Q
1
# Only 1 is a perfect square <= 1
13
29
countSquares(5) returns 2
2.
# 1, 4 are perfect squares <= 5
0E
24
countSquares(55) returns 7
P2
5.
_Q
.5
17
7. Attempt any one part of the following:
TU
|1
in lst are alternately odd and even, starting with an even number.
Otherwise it returns False. For example:
:
14
AKTU_QP20E290QP | 12-Mar-2021
Downloaded 14:07:56 | 117.55.242.131
from : uptukhabar.net