Printed Page: 1 of 2
Subject Code: BCC402
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
BTECH
(SEM IV) THEORY EXAMINATION 2023-24
PYTHON PROGRAMMING
TIME: 3 HRS M.MARKS: 70
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
SECTION A
1. Attempt all questions in brief. 2 x 7 = 14
a. Give difference between = = and is operator.
b. How we print the character of a given ASCII value in Python?
c. Can you use else with a for loop? If so, when is it executed?
d. What will be the output of the following Python code?
l= [1, 0, 0, 2, ' hi', ' ', []]
print(list(filter(bool, l))
e. Describe the purpose of the split() method in string manipulation.
f. What does the readline() function return when it reaches the end of a file?
g. Which function is used to create identity matrix in NumPy?
4
19
SECTION B
92
5.
_2
2. Attempt any three of the following: 7 x 3 = 21
.6
P2
a. Explain the concept of dynamic typing in Python with an example.
40
b. Explain how to define a list in Python. Write a Python program to remove
4E
.2
duplicates from a list and print the resulting list.
15
P2
c. Explain the concept of functions in Python. Write a function that takes a list of
|1
Q
numbers and returns the sum of all the numbers in the list.
PM
d. Write a Python program to read a file named “ABC.txt” and count the number
of lines, words, and characters in the file.
e. Explain the basic usage of matplotlib for plotting graphs. Write a Python
02
program to plot a simple line graph showing the relationship between x = [1, 2,
:
40
3, 4, 5] and y = [1, 4, 9, 16, 25].
1:
SECTION C
24
3. Attempt any one part of the following: 7x1=7
20
(a) Explain for and while loops used in Python with appropriate example.
g-
(b) Write a Python Program to find the LCM of two numbers.
Au
4. Attempt any one part of the following: 7x1=7
7-
(a) Write a program takes two strings and checks common letters in both the
|0
strings.
Enter first string: Hari
Enter second string: Hale
The common letters are:
H
a
(b) Write a Python Program to find the sum all the items in a dictionary.
For example if d={'A':100,'B':540,'C':239}then output should be 879.
1|Page
QP24EP2_292 | 07-Aug-2024 1:40:02 PM | 115.240.65.194
Printed Page: 2 of 2
Subject Code: BCC402
0Roll No: 0 0 0 0 0 0 0 0 0 0 0 0 0
BTECH
(SEM IV) THEORY EXAMINATION 2023-24
PYTHON PROGRAMMING
TIME: 3 HRS M.MARKS: 70
5. Attempt any one part of the following: 7x1=7
(a) Explain the concept of a set in Python and its characteristics. How elements are
added or removed in set.
(b) Explain how lambda functions can be used within a list comprehension. Write a
Python program that uses a lambda function within a list comprehension to
convert a list of temperatures in Celsius to Fahrenheit.
6. Attempt any one part of the following: 7x1=7
(a) Explain different file opening modes also write a Python Program to read a file
and capitalize the first letter of every word in the file.
(b) What do you mean by generators in Python? How it is created in Python?
7. Attempt any one part of the following: 7x1=7
(a) Describe how to generate random numbers using NumPy. Write a Python
program to create an array of 5 random integers between 10 and 50.
(b) Explain the concept of DataFrame in pandas. Write a Python program to create
4
a DataFrame from a dictionary and print it.
19
92
5.
_2
.6
P2
40
4E
.2
15
P2
|1
Q
PM
:02
40
1:
24
20
g-
Au
7-
|0
2|Page
QP24EP2_292 | 07-Aug-2024 1:40:02 PM | 115.240.65.194
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