AKTU Python Programming (KNC302) Question Paper 2020-21
| University | Dr. A.P.J. Abdul Kalam Technical University (AKTU), Lucknow |
|---|---|
| Course | B.Tech, Semester III |
| Subject | Python Programming (KNC302) |
| Exam | Theory Examination 2020-21 (odd semester) |
| Time · Marks | 3 hours · 100 marks |
| Source | AKTU question paper, from the ABESIT question paper bank |
Note: Attempt all Sections. If require any missing data; then choose suitably.
Section A
Q1. Attempt all questions in brief
- What is the use of “ raise ” statement? Describe with an example.
- Write a recursive Python function “ rprint ” to print all elements in a list in reverse.
rprint([]) prints nothingrprint([1,2,3]) prints 3 2 1 - Describe the behavior of “ range (s, e) ” in Python.
- Explain the use of “ with ” construct in Python with an example program.
- Which of the following statements produce an error in Python?
x, y, z = 1,2,3 # s1a, b = 4,5,6 # s2u = 7,8,9 # s3
( List all the statements that have error.) - Explain the role of precedence with an example.
- How do you read an input from a user in Python to be used as an integer in the rest of the program? Explain with an example.
- Consider the program:
x = ['12', 'hello', 456]x[0] *= 3x[1][1] = 'bye'
Explain why this program generates an error. - What is the output of the following program? (lambda x,y : y - 2*x) (1, 11)
- Explain the use of lt function in a class Python?
Section B
Q2. Attempt any three of the following
- Write a Python function removekth(s, k) that takes as input a 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,
removekth(“PYTHON”, 1) returns “PTHON”removekth(“PYTHON”, 3) returns “PYTON”removekth(“PYTHON”, 0) returns “YTHON”removekth(“PYTHON”, 20) returns “PYTHON” - Write a Python function average to compute the average of a list of numbers. The function must use try-except to handle the case where the input list is empty. Further, in that case the average for the empty list should be set to 0.0 using the except block.
- Describe the differences between a linear search and a binary search?
- Write a function lessthan(lst, k) to return list of numbers less than k from a list lst . The function must use list comprehension. Example: lessthan([1, -2, 0, 5, -3], 0) returns [-2, -3]
- Write a program factors(N) that returns a list of all positive divisors
of N ( N>=1 ). For example:factors(6) returns [1,2,3,6]factors(1) returns [1]factors(13) returns [1,13]
Section C
Q3
Attempt any one part of the following
- How can you create Python file that can be imported as a library as well as run as a standalone script?
- Describe the difference between
import library
andfrom library import *
when used in a python program. Here library is some python library .
Q4
Attempt any one part of the following
- Write a function makePairs that takes as input two lists of equal 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 [] - Show an example where both Keyword arguments and Default arguments are used for the same function in a call. Show both the definition of the function and its call.
Q5
Attempt any one part of the following
- Explain why Python is considered an interpreted language.
- What is short circuit evaluation? What is printed by the following
Python program?a = 0b = 2c = 3x = c or aprint(x)
Q6
Attempt any one part of the following
- Write a Python program, triangle(N) , that prints a right triangle having base and height consisting of N * symbols as shown in these examples:
triangle(3) prints:******triangle(5) prints:*************** - Write a Python program, countSquares(N) , that returns the count of perfect squares less than or equal to N ( N>1 ). For example:
countSquares(1) returns 1# Only 1 is a perfect square <= 1countSquares(5) returns 2# 1, 4 are perfect squares <= 5countSquares(55) returns 7# 1, 4, 9, 16, 25, 36, 49 <= 55
Q7
Attempt any one part of the following
- Write a Python function, alternating(lst) , that takes as argument a sequence lst . The function returns True if the elements in lst are alternately odd and even, starting with an even number .
Otherwise it returns False . For example:alternating([10, 9, 9, 6]) returns Falsealternating([10, 15, 8]) returns Truealternating([10]) returns Truealternating([]) returns Truealternating([15, 10, 9]) returns False - Write a Python function, searchMany(s, x, k) , that takes as argument a sequence s and integers x, k (k>0) . The function returns
True if there are at most k occurrences of x in s . Otherwise it returns
False . For example:searchMany([10, 17, 15, 12], 15, 1) returns TruesearchMany([10, 12, 12, 12], 12, 2) returns FalsesearchMany([10, 12, 15, 11], 17, 18) returns True
Short on time? See the most repeated AKTU Python Programming questions across all years.
Other years
More AKTU Python Programming papers on LearnAIFast.
This paper is reproduced for study purposes only. Copyright belongs to AKTU. Source: the question paper bank of ABES Institute of Technology, an AKTU-affiliated college. If you own the copyright and want it removed, email learnwithskillnest@gmail.com and we will take it down.