Pyp2 21
Pyp2 21
B.TECH
(SEM III) THEORY EXAMINATION 2020-21
PYTHON PROGRAMMING
Time: 3 Hours Total Marks: 100
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
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
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,
SECTION C
3. Attempt any one part of the following:
Q no. Question Marks CO
a. How can you create Python file that can be imported as a library as 10 5
well as run as a standalone script?
makePairs([1,3,5,7],[2,4,6,8])
returns [(1,2),(3,4),(5,6),(7,8)]
makePairs([],[])
returns []
triangle(3) prints:
*
**
***
triangle(5) prints:
*
**
***
****
*****
b. Write a Python program, countSquares(N), that returns the count 10 4
of perfect squares less than or equal to N (N>1). For example:
countSquares(1) returns 1
# Only 1 is a perfect square <= 1
countSquares(5) returns 2
# 1, 4 are perfect squares <= 5
countSquares(55) returns 7
# 1, 4, 9, 16, 25, 36, 49 <= 55