[Link].
(Computer Science and
Engineering) Semester-IV
Subject: Python Programming (BCO081B)
Marks:64
Assignment#3
Section-A Answer the following Questions: (5*2=10marks)
1. Differentiate between List and Tuple in Python.
2. What is indexing and slicing? Explain with an example.
3. Define Set. How is it different from Dictionary?
4. What is the purpose of the zip() function in Python?
5. What is the local and global scope of a variable? Define with example.
Section-B Answer the following Questions: (7x3=21Marks)
2. Explain basic operations that can be performed on Lists, Tuples, Dictionaries and Sets
(Include suitable examples).
4. Write a Python program to define a function that takes two numbers and returns their sum and
product. Demonstrate returning multiple values.
5. Explain different types of parameters in Python functions with examples: Positional arguments,
Keyword arguments, Default parameter.
Section-C Answer the following Questions: (11x3=33Marks)
1.(a)Write a program to remove duplicates from a list using Set.
(b) Write a program to combine two lists into a dictionary using the zip() function.
2. (a) Write a recursive function to calculate power of a number (x^n).
(b). Write a Python program using Lambda function to find square of a number and use lambda
with map() to find squares of elements in a list.
3. Write the output for the following codes:
1. a = [1, 2, 3] 4. a = [[1, 2], [3, 4]] 7. t = (1, [2, 3]) 10. t = (1, 2, 3)
b=a b = [Link]() t[1].append(4) a, b, c = t
a += [4] a[0][0] = 10 print(t) print(a + b + c)
print(b) print(b)
2. t = (1, 2, 3) 5. s = {1, 2, 3} 8. d = {'a': 1, 'b': 2} 11. d = {'a': 1}
print(id(t), id(t + (4,))) print(s ^ {2, 3, 4}) print([Link]('a', 100)) print([Link]('b') is None)
3. d = {'a': 1, 'b': 2} 6. def f(x): 9. def f(x):
print({k:v for k,v in [Link]() if v > 1}) return x, x*2 x = x + [10]
a, b = f(3) return x
print(a, b) a = [1, 2]
f(a)
print(a)