Student Name: Gagandeep Singh
Date: 07/08/2025
Username: 22304252
Exam: SCAM-7215 Python Programming
UID: 295581
Section B (Q41–55): Very short answers, 2 marks each, attempt
any 10
41. A Python program has input (using input()), processing (logic), and output (print()).
42. Mutable objects (lists) can change; immutable (tuples) cannot. Lists are slower due to memory
reallocations.
43. Reverse: s[::-1], Palindrome: s == s[::-1], Vowel Count: sum(1 for c in s if c in 'aeiou')
44. If: one condition, If-else: two paths, Elif: multiple conditions.
45. Loop 1–100, check if a number is prime using for/while and skip using continue/break.
46. [x**0.5 for x in range(1, 11)]
47. Examples: lower(), upper(), replace(), split(), find()
48. List: mutable sequence, String: immutable text
49. List: [], Tuple: (), Set: {}, Dictionary: {k:v}. CRUD = Create, Read, Update, Delete
50. Functions group code into reusable blocks. def greet(): print("Hi")
51. Factorial using recursion: if n==0 return 1 else return n*fact(n-1). Iterative uses loops.
52. Lambda: small anonymous functions
Map: apply function to iterable
Filter: filter items
Reduce: apply function cumulatively
53. Use open(), read(), write().
54. Accept list, return {x: x**3 for x in list}
55. Iterator: object with __next__()
Generator: uses yield to return lazy values.
Section C (Q56–58): Long answers, 5 marks each, attempt any 2
56. Data Structures and Mutability:
List (mutable): [1,2,3]; Tuple (immutable): (1,2); Set (no duplicates): {1,2}; Dict (key-value): {"a":1}
Mutability helps in dynamic data updates, important in real-time apps.
57. File Read, Clean & Word Frequency:
import string with open("[Link]") as f: text = [Link]().lower() for p in [Link]: text =
[Link](p, "") words = [Link]() freq = {} for w in words: freq[w] = [Link](w, 0) + 1 with
open("[Link]", "w") as f: for k,v in [Link](): [Link](f"{k}: {v}\n")
58. OOP Concepts in Python:
class Library: def __init__(self, name): self.__name = name [Link] = [] def add_book(self, b):
[Link](b) def display_books(self): print([Link]) class Student(Library): def
__init__(self, name, sid): super().__init__(name) [Link] = sid def display_books(self):
print("Student Books:", [Link]) lib = Student("City Lib", "S101") lib.add_book("Python")
lib.display_books() Encapsulation (private __name), Inheritance (Student -> Library), Overriding
(display_books)