■ CSE-20 TIMEOUT EXAM – PYTHON
Duration: 3 Hours Max Marks: 100
■ Instructions
- Answer ALL questions.
- Partial credit will be awarded for correct reasoning even if the final answer is not fully correct.
- Use clear, commented code.
- Show working/explanation wherever asked.
Part 1 – Advanced Code Tracing (30 Marks)
(Answer ALL, each 10 marks)
Q1. List and Function Scope (10 marks)
def modify_list(my_list): my_list.append(4) new_list = my_list new_list[0] = 99 return new_list l = [1,
2, 3] m = modify_list(l) print(l) print(m)
- Write exact output.
- Explain referencing and mutability.
Q2. Dictionary and Nested Data Structures (10 marks)
data = { 'a': [1, 2, 3], 'b': {'x': 10, 'y': 20}, 'c': 'hello' } data['a'].append(data['b']['y']) data['b']['y'] = 50
data['c'] += ' world' print(data['a'][3]) print(data['b']['y'])
- Write exact output.
- Explain why list `a` does not reflect later change in `b['y']`.
Q3. Generators and Lazy Evaluation (10 marks)
def fibonacci_gen(limit): a, b = 0, 1 while a < limit: yield a a, b = b, a + b gen = fibonacci_gen(10) for
num in gen: if num % 2 != 0: print(num) break print(next(gen))
- Write exact output.
- Explain how generator resumes after `break`.
Part 2 – Core Programming Problems (40 Marks)
(Answer ANY FOUR, each 10 marks)
Q4. Algorithmic Thinking (10 marks)
Implement `find_unique_pairs(numbers, target_sum)` efficiently (hash-based).
Example: `find_unique_pairs([3,5,2,-4,8,11,1,6], 7)` → `[(11,-4), (1,6), (2,5)]`. No O(n²) brute force.
Q5. File I/O + Error Handling (10 marks)
Write `process_student_data(input_file, output_file)` that:
- Reads student scores from CSV.
- Writes average score for each student to new file.
- Handles `FileNotFoundError` gracefully.
Q6. Object-Oriented Programming (10 marks)
Create a base class Shape with method area(). Subclasses Rectangle, Circle implement `area()`.
Write `print_areas(shapes_list)`.
Q7. String and Dictionary Manipulation (10 marks)
Write `analyze_text(text)` returning word_counts and char_counts (ignore punctuation, lowercase).
Q8. Recursion (10 marks)
Write recursive `flatten_list(nested_list)` that converts nested lists into single flat list.
Part 3 – Advanced Data Structures & Design (30 Marks)
(Answer ANY THREE, each 10 marks)
Q9. Queue Class (10 marks)
Implement Queue (FIFO) with enqueue, dequeue, is_empty, size.
Q10. Matrix Rotation (10 marks)
Write program to rotate a square matrix 90° clockwise in-place.
Q11. Case Study – Mini ATM (10 marks)
Design ATM system with OOP: login, withdraw, deposit, check balance, error handling.
Q12. Bit Manipulation (10 marks)
Write `count_ones(n)` returning number of 1s in binary rep using bitwise operators.
Q13. Real-World Application (10 marks)
CSV with emp_id, name, salary. Load, find average salary, print employees earning above
average.
Marking Scheme
- Part 1 (Tracing): 30 marks
- Part 2 (Core Problems): 40 marks
- Part 3 (Advanced / Case Study): 30 marks
Total = 100 marks