0% found this document useful (0 votes)
4 views

Python PYQ

The document outlines the structure and content of a Python Programming examination for BTech students, including various sections with questions on topics like list comprehension, operators, functions, and data structures. It consists of multiple-choice and descriptive questions, requiring students to demonstrate their understanding of Python concepts and coding skills. The exam is designed to assess knowledge across different aspects of Python programming over a duration of 3 hours.
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)
4 views

Python PYQ

The document outlines the structure and content of a Python Programming examination for BTech students, including various sections with questions on topics like list comprehension, operators, functions, and data structures. It consists of multiple-choice and descriptive questions, requiring students to demonstrate their understanding of Python concepts and coding skills. The exam is designed to assess knowledge across different aspects of Python programming over a duration of 3 hours.
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/ 10

Printed Page: 1 of 3

Subject Code: BCC302


0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

BTECH
(SEM III) THEORY EXAMINATION 2023-24
PYTHON PROGRAMMING
TIME: 3HRS M.MARKS: 70

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
a. Describe the concept of list comprehension with a suitable example 2
b. Differentiate between / and // operator with an example 2
c. Compute the output of the following python code: 2
def count(s):
for str in string.split():
s = “&”.join(str)
return s
print(count(“Python is fun to learn.”))
d. How to use the functions defined in library.py in main.py 2
e. Describe the difference between linspace and argspace. 2
f. Explain why the program generates an error. 2
90

2
x = [‘12’, ’hello’, 456]

13
_2

x[0] *= 3

2.
x[1][1]=’bye’
P2

24
g. Describe about different functions of matplotlib and pandas. 2
4D

5.
SECTION B

.5
P2

2. Attempt any three of the following:


17
Q

a. Illustrate Unpacking tuples, mutable sequences, and string concatenation with 7


|1

examples
b. Illustrate different list slicing constructs for the following operations on the 7
3 0

following list:
0:

L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
:2

1. Return a list of numbers starting from the last to second item of the list
13

2. Return a list that start from 3rd item to second last item.
3. Return a list that has only even position elements of list L to list M.
4

4. Return a list that starts from the middle of the list L.


02

5. Return a list that reverses all the elements starting from element at index
-2

0 to middle index only and return the entire list.


03

Divide each element of the list by 2 and replace it with the remainder.
c. Construct a function perfect_square(number) that returns a number if it is a perfect 7
2-

square otherwise it returns -1.


|1

For example:
perfect_square(1) returns 1
perfect_square (2) returns -1
d. Construct a program to change the contents of the file by reversing each character 7
separated by comma:
Hello!!
Output
H,e,l,l,o,!,!
e. Construct a plot for following dataset using matplotlib : 7
1|Page
QP24DP2_290 | 12-03-2024 13:20:30 | 117.55.242.132
Printed Page: 2 of 3
Subject Code: BCC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

BTECH
(SEM III) THEORY EXAMINATION 2023-24
PYTHON PROGRAMMING
TIME: 3HRS M.MARKS: 70

Food Calories Potassium fat


Meat 250 40 8
Banana 130 55 5
Avocados 140 20 3
Sweet
Potatoes 120 30 6
Spinach 20 40 1
Watermelon 20 32 1.5
Coconut
water 10 10 0
Beans 50 26 2
Legumes 40 25 1.5
Tomato 19 20 2.5
SECTION C
90

2
3. Attempt any one part of the following:

13
_2

a. Determine a python function removenth(s,n) that takes an input a string and an 7

2.
integer n>=0 and removes a character at index n. If n is beyond the length of s,
P2

24
then whole s is returned. For example:
4D

5.
removenth(“MANGO”,1) returns MNGO
removenth(“MANGO”,3) returns MANO
.5
P2

17
Q

b. Construct a program that accepts a comma separated sequence of words as input 7


|1

and prints the words in a comma-separated sequence after sorting them


alphabetically.
3 0

Suppose the following input is supplied to the program:


0:

without, hello, bag, world


:2

Then, the output should be:


13

bag, hello, without, world


4. Attempt any one part of the following:
4
02

a. A website requires the users to input username and password to register. Construct 7
a program to check the validity of password input by users.
-2

Following are the criteria for checking the password:


03

1. At least 1 letter between [a-z]


2-

2. At least 1 number between [0-9]


|1

3. At least 1 letter between [A-Z]


4. At least 1 character from [$#@]
5. Minimum length of transaction password: 6
6. Maximum length of transaction password: 12
Your program should accept a sequence of comma separated passwords and will
check them according to the above criteria. Passwords that match the criteria are
to be printed, each separated by a comma
b. Explore the working of while, and for loop with examples. 7
5. Attempt any one part of the following:

2|Page
QP24DP2_290 | 12-03-2024 13:20:30 | 117.55.242.132
Printed Page: 3 of 3
Subject Code: BCC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

BTECH
(SEM III) THEORY EXAMINATION 2023-24
PYTHON PROGRAMMING
TIME: 3HRS M.MARKS: 70

a. Construct a function ret smaller(l) that returns smallest list from a nested list. If 7
two lists have same length then return the first list that is encountered. For
example:

ret smaller([ [ -2, -1, 0, 0.12, 1, 2], [3, 4, 5], [6 , 7, 8, 9, 10], [11, 12, 13, 14, 15]])
returns [3,4,5]
ret smaller([ [ -2, -1, 0, 0.12, 1, 2], [‘a’, ’b’, ’c’, ’d’, 3, 4, 5], [6 , 7, 8, 9, 10], [11,
12, 13, 14, 15]]) returns [6 , 7, 8, 9, 10]
b. Construct following filters: 7
1. Filter all the numbers
2. Filter all the strings starting with a vowel
3. Filter all the strings that contains any of the following noun: Agra,
Ramesh, Tomato, Patna.
Create a program that implements these filters to clean the text.
6. Attempt any one part of the following:
a. Change all the numbers in the file to text. Construct a program for the same. 7
90

2
Example:

13
_2

Given 2 integer numbers, return their product only if the product is equal to or lower

2.
than 10.
P2

24
And the result should be:
4D

Given two integer numbers, return their product only if the product is equal to or

5.
lower than one zero
.5
P2

b. Construct a program which accepts a sequence of words separated by whitespace 7


17
as file input. Print the words composed of digits only.
Q

|1

7. Attempt any one part of the following:


a. Construct a program to read cities.csv dataset, remove last column and save it in 7
3 0

an array. Save the last column to another array. Plot the first two columns.
0:

b. Design a calculator with the following buttons and functionalities like addition, 7
:2

subtraction, multiplication, division and clear.


13
4
02
-2
03
2-
|1

3|Page
QP24DP2_290 | 12-03-2024 13:20:30 | 117.55.242.132
Printed Pages: 2 Sub Code:KNC-402

Paper Id: 238061 Roll No.

B.Tech.
(SEM IV) THEORY EXAMINATION 2022-23
PYTHON PROGRAMMING

Time: 3 Hours Total Marks: 100

Note: Attempt all Sections. If require any missing data; then choose suitably.

SECTION A

1. Attempt all questions in brief. 2 x 10 = 20


a. Define the programming cycle for Python.
b. Describe the use of class `__init__()` method.
c. Explain features of any two Python IDEs.
d. Discuss the purpose of the break and continue statement in loops.
e. Explain mutable sequences in Python.
f. Explain the output of following function.
90

2
defprintalpha (abc_list, num_list):

13
for char in abc_list:
_2

2.
for num in num_list:
P2

24
print(char, num)
return
3E

5.
printalpha (['a', 'b', 'c'], [1, 2, 3])

.5
P2

g. Discuss the special methods __le__ and __ne__.


h. Discuss various file opening modes of python.
17
Q

|1
i. Compare assert, try-except and raise statements.
j. Write python function to perform linear search.
0
:3
: 24
13

SECTION B
3
02

2. Attempt any three of the following: 10x3=30


-2
08

a. Write Python code snippet to display n terms of Fibonacci series using recursion.
1-

b. Write and explain an algorithm through python code to generate prime numbers.
|0

c. Compare list and tuple data structure with suitable examples. Explain the concept
of list comprehension.
d. Explain the python implementation of stack ADT.
e. Describe python program to implement selection sort. Simulate your code on the
following data
2,52,1,5,2,54,62,64.

QP23EP2_290 | 01-08-2023 13:24:30 | 117.55.242.132


SECTION C
3. Attempt any one part of the following: 10x1=10
a. Discuss various categories of operators in python. Find and explain stepwise
solution of following expressions if a=3, b=5, c=10.

i) a &b<<2//5**2+c^b
ii) b>>a**2<<2 >> b**2^c**3

b. Discuss why python is interpreted language. Explain history and features of


python while comparing python version 2 and 3.

4. Attempt any one part of the following: 10x1=10


a. Write a python program to count the vowels present in given input string.
Explain the output of program through example.
b. Write a program that accepts sequence of lines as input and prints the lines
after making all characters in the sentence capitalized.
e.g. If Input:
Hello world
Practice makes perfect
Then, Output:
90

2
HELLO WORLD

13
_2
PRACTICE MAKES PERFECT

2.
P2

24
5. Attempt any one part of the following: 10x1=10
3E

5.
.5
P2

a. Discuss list data structure of python. Explain various inbuilt methods of list with
suitable example of each.
17
Q

b. Compare list and dictionary data structure. Explain various dictionary methods
|1
with suitable examples of each.
0
:3

6. Attempt any one part of the following: 10x1=10


: 24

a. Discuss the concept of Iterators in python. Explain, how we can create text file
13

in python? Describe python program to write the number of letters and digits in
given input string into a File object.
3
02

b. Illustrate through examples, how we can implement different type of


inheritance in python? Explain the static, instance and class method through
-2

suitable example.
08
1-

7. Attempt any one part of the following: 10x1=10


|0

a. Explain the Tower of Hanoi problem and its recursive solution in Python.
b. Write python program to implement merge sort algorithm. Discuss, how we can
compare the time complexity of two algorithms?

QP23EP2_290 | 01-08-2023 13:24:30 | 117.55.242.132


Printed Page: 1 of 1
Subject Code: KNC402
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

BTECH
(SEM IV) THEORY EXAMINATION 2021-22
PYTHON PROGRAMMING
Time: 3 Hours Total Marks: 50
Note: Attempt all Sections. If you require any missing data, then choose suitably.

SECTION A
1. Attempt all questions in brief. 2.5*4 = 10
Qno Questions CO
(a) Discuss why Python is called as dynamic and strongly typed language? 1
(b) How pass statement is different from a comment? 2
(c) Write a for loop that prints numbers from 0 to 57, using range function. 2
(d) What is the difference between Python Arrays and Lists? 3
SECTION B
2. Attempt any two of the following: 4*2 = 8
Qno Questions CO
(a) Write a python function named ComputeAverage to find average of a list of 3
numbers. It should handle the exception if the list is empty and return 0 in
that case.
(b) Implement the binary search technique. 5
(c) Explain the use of break and continue with a suitable example. 2
90

2
13
SECTION C
_2

3. Attempt any two part of the following: 4*2 = 8

2.
Qno Questions CO
P2

24
(a) What do you mean by operator precedence and associativity. Explain. 1
2E

5.
(b) Write short notes on 1
.5
P2

i. The programming cycle for python


17
ii. Type conversion in python
Q

(c) Write Python program to swap two numbers without using 1


|1

Intermediate/Temporary variables. Prompt the user for input.


4. Attempt any two part of the following: 4*2 = 8
6

Qno Questions CO
2
2:

(a) Write a program to check an input number is prime or not. 2


:3

(b) Write a program that accepts a sentence and calculate the number of digits, 2
13

uppercase and lowercase letters.


(c) Write a program to check an input year is leap year or not. 2
2

5. Attempt any two part of the following: 4*2 = 8


02

Qno Questions CO
-2

(a) There is a file named Input.Txt. Enter some positive numbers into the file 4
08

named Input.Txt. Read the contents of the file and if it is an odd number
write it to ODD.TXT and if the number is even, write it to EVEN.TXT
2-

(b) Discuss Exceptions and Assertions in Python. Explain with a suitable 4


|0

example. Explain any two built-in exceptions.


(c) What is the significance of module in Python? What are the methods of 4
importing a module? Explain with suitable example
6. Attempt any two part of the following: 4*2 = 8
Qno Questions CO
(a) What do you mean by recursion? Write a recursive function to compute the 5
factorial of an input number N.
(b) Implement selection sort using Python 5
(c) What are different types of inheritance supported by Python? Explain. 4

QP22EP2_290 | 02-08-2022 13:32:26 | 117.55.242.132


Printed Page: 1 of 4
Subject Code: KNC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

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

b. Write a recursive Python function “rprint” to print all elements in a 2 3


list in reverse.
rprint([]) prints nothing
rprint([1,2,3]) prints 3 2 1

c. Describe the behavior of “range (s, e)” in Python. 2 3

d. Explain the use of “with” construct in Python 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

g. How do you read an input from a user in Python to be used as an integer 2 5


|1

in the rest of the program? Explain with an example.


AK

6
:5

h. Consider the program: 2 1


07

x = ['12', 'hello', 456]


:
14

x[0] *= 3
x[1][1] = 'bye'
1
02

Explain why this program generates an error.


-2
ar

i. What is the output of the following program? 2 5


M

(lambda x,y : y - 2*x) (1, 11)


2-
|1

j. Explain the use of lt function in a class Python? 2 5

AKTU_QP20E290QP | 12-Mar-2021 14:07:56 | 117.55.242.131


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,

removekth(“PYTHON”, 1) returns “PTHON”


removekth(“PYTHON”, 3) returns “PYTON”
removekth(“PYTHON”, 0) returns “YTHON”
removekth(“PYTHON”, 20) returns “PYTHON”

b. Write a Python function average to compute the average of a list of 10 3


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.

c. Describe the differences between a linear search and a binary search? 10 5

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

lessthan([1, -2, 0, 5, -3], 0) returns [-2, -3]

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

factors(13) returns [1,13]


|1
AK

6
:5

SECTION C
07

3. Attempt any one part of the following:


:

Q no. Question Marks CO


14

a. How can you create Python file that can be imported as a library as well 10 5
1

as run as a standalone script?


02
-2

b. Describe the difference between 10 5


ar

import library
and
M
2-

from library import *


when used in a python program. Here library is some python
|1

library.

AKTU_QP20E290QP | 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 []

b. Show an example where both Keyword arguments and Default 10 4


arguments are used for the same function in a call. Show both the
definition of the function and its call.

5. Attempt any one part of the following:

P
Q no. Question 0Q Marks CO
a. Explain why Python is considered an interpreted language. 10 1

1
13
29

b. What is short circuit evaluation? What is printed by the following 10 1

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

AKTU_QP20E290QP | 12-Mar-2021 14:07:56 | 117.55.242.131


Printed Page: 4 of 4
Subject Code: KNC302
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0

6. Attempt any one part of the following:


Q no. Question Marks CO
a. Write a Python program, triangle(N), that prints a right triangle 10 3
having base and height consisting of N * symbols as shown in these
examples:

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:

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

# 1, 4, 9, 16, 25, 36, 49 <= 55

5.
_Q

.5
17
7. Attempt any one part of the following:
TU

|1

Q no. Question Marks CO


AK

a. Write a Python function, alternating(lst), that takes as 10 4


6
:5

argument a sequence lst. The function returns True if the elements


07

in lst are alternately odd and even, starting with an even number.
Otherwise it returns False. For example:
:
14

alternating([10, 9, 9, 6]) returns False


alternating([10, 15, 8]) returns True
1
02

alternating([10]) returns True


alternating([]) returns True
-2

alternating([15, 10, 9]) returns False


ar
M
2-

b. Write a Python function, searchMany(s, x, k), that takes as 10 3


argument a sequence s and integers x, k (k>0). The function returns
|1

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 True
searchMany([10, 12, 12, 12], 12, 2) returns False
searchMany([10, 12, 15, 11], 17, 18) returns True

AKTU_QP20E290QP | 12-Mar-2021 14:07:56 | 117.55.242.131

You might also like