ASSIGNMENT –III
Subject: Python Programming
Subject code:
Faculty Name:
Section: Session: 2025-26
[Link] Question CO/BTL Competitive/Univ.
.
1 Illustrate different list slicing constructs (BCC302.3, K3) Univ. 2023-24
for the following operations on the
following list: L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
1. Return a list of numbers starting from
the last to second item of the list
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. Return a list that starts from the middle
of the list L.
5. Return a list that reverses all the
elements starting from element at index 0
to middle index only and return the entire
list.
Divide each element of the list by 2 and
replace it with the remainder.
II Construct a function (BCC302.3, K3) Univ. 2023-24
perfect_square(number) that returns a
number if it is a perfect square otherwise
it returns -1. For example:
perfect_square(1) returns 1 perfect_square
(2) returns -1
III Compare list and tuple data structure with (BCC302.3, K3) Univ. 2022-23
suitable examples. Explain concept of list
comprehension.
IV Write a python function to display n terms (BCC302.3, K3) Univ. 2022-23
of Fibonacci series using recursion.
V (BCC302.3, K3) Gate 2024
Consider the following Python code:
1. def count(child_dict, i):
2. if i not in child_dict.keys():
3. return 1
4. ans = 1
5. for j in child_dict[i]:
6. ans += count(child_dict, j)
7. return ans
8.
9. child_dict = dict()
10. child_dict[0] = [1, 2]
11. child_dict[1] = [3, 4, 5]
12. child_dict[2] = [6, 7, 8]
13. print(count(child_dict, 0))
Which ONE of the following is the output
of this code?
VI (BCC302.3, K3) Gate 2025
Consider the following Python code
snippet.
1. def f(a,b):
2. if (a==0):
3. return b
4. if (a%2==1):
5. return 2*f((a-1)/2,b)
6. return b+f(a-1,b)
7. print(f(15,10))
8.
The value printed by the code snippet is
____________. (Answer in integer)
VII Write a Python program that: (BCC302.3, K3) (Industry-
1. Takes a paragraph as input Oriented)
(string).
2. Splits it into individual words.
3. Counts how many times each
word appears.
4. Stores the result in a dictionary
and displays the word-frequency
pairs.
VIII Create a Python program to maintain (BCC302.3, K3) (Industry-
student marks. The program should: Oriented)
1. Take input of student names and
their marks in three subjects.
2. Store this in a dictionary where the
key is the student name and the
value is a list of marks.
3. Write a function to calculate and
display the average marks of each
student.