Here are the important short and long questions of Unit 3, Programming Fundamentals, from the Federal Board (FBISE) 2nd Year Computer Science course (HSSC-II, Intermediate Part II), solved in full for the Annual Examination 2027.
| Unit | 3: Programming Fundamentals |
|---|---|
| Class | 2nd Year (HSSC-II), Federal Board |
| Subject | Computer Science |
| Contents | Short and long questions with answers |
| Exam | FBISE Annual Examination 2027 |
Short Questions with Answers: Unit 3
Q1. Here is the sample data in table format: [Model Paper 2025 (New Curriculum)] (1.5+1.5)
Use this data to compare storage and retrieval using a nested list and a dictionary in context to Python.
Answer:
-
Nested list: data is stored in order and accessed by index position.
students = [[101, “Ali”, 85], [102, “Babar”, 90], [103, “Sana”, 78]]
print(students[1][2]) # 90 (Babar’s grade) β need to know position
-
Dictionary: data is stored as keyβvalue pairs, using Student ID as the key.
students = {101: {“name”: “Ali”, “grade”: 85},
102: {“name”: “Babar”, “grade”: 90},
103: {“name”: “Sana”, “grade”: 78}}
print(students[102][“grade”]) # 90 β direct lookup by ID
| Nested list | Dictionary |
|---|---|
| Accessed by numeric index; must search (loop) to find a student by ID | Accessed directly by key (Student ID) |
| Search by ID takes O(n) time | Lookup is fast, about O(1) |
| Order-based; less readable | Self-describing, readable and easy to update |
Q2. How is a file opened and closed in Python? [Annual 2026 β Paper B] (1.5+1.5)
Answer:
-
Opening a file: the built-in open() function is used with the file name and mode (‘r’ read, ‘w’ write, ‘a’ append, ‘rb’ binary).
f = open(“data.txt”, “r”)
text = f.read()
-
Closing a file: close() releases the file and saves changes.
f.close()
-
Better way (with statement): the file closes automatically.
with open(“data.txt”, “w”) as f:
f.write(“Hello”)
Q3. Write down three drawbacks of functional programming. [Annual 2026 β Paper D] (1Γ3)
Answer:
-
Difficult to learn and read for beginners: concepts like recursion, higher-order functions and immutability are hard, and code can be less intuitive.
-
Performance and memory overhead: immutable data means new copies are created instead of being changed, and heavy recursion uses more memory (stack) and may be slower.
-
Hard to handle state and I/O: real programs need input/output, databases and user interaction (side effects), which are awkward in pure functional style. There are also fewer libraries and developers.
Q4. What is the difference between text and binary files? Any three points. [Annual 2026 β Paper D] (1Γ3)
Answer:
| Text file | Binary file |
|---|---|
| Stores data as human-readable characters (ASCII/Unicode) | Stores data in binary form (0s and 1s), the same as in memory |
| Can be opened and read in a text editor (Notepad) | Not readable in a text editor; needs a specific program |
| End of line is converted (n); larger size, slower | No conversion; compact, faster read/write |
| e.g. .txt, .csv, .py | e.g. .jpg, .exe, .mp3, .dat |
Long Questions with Answers: Unit 3
Q1. Design a Vehicle Management System using Object-Oriented Programming (OOP) in Python. Requirements: [Model Paper 2025 (New Curriculum)] (2+2+1)
(a) Create a Vehicle class with attributes: type, brand, model and mileage.
(b) Implement a constructor to initialize these attributes. Also add methods to update mileage and display details.
(c) Create two vehicle objects, update their mileage, and display their details.
Answer:
class Vehicle:
# (b) constructor initialises the attributes
def __init__(self, vtype, brand, model, mileage):
self.type = vtype
self.brand = brand
self.model = model
self.mileage = mileage
# method to update mileage
def update_mileage(self, km):
if km >= 0:
self.mileage += km
else:
print(“Mileage cannot be negative”)
# method to display details
def display(self):
print(f”Type: {self.type}, Brand: {self.brand}, “
f”Model: {self.model}, Mileage: {self.mileage} km”)
# (c) create two objects, update mileage and display
v1 = Vehicle(“Car”, “Toyota”, “Corolla 2022”, 15000)
v2 = Vehicle(“Motorbike”, “Honda”, “CD-70”, 8000)
v1.update_mileage(500)
v2.update_mileage(250)
v1.display()
v2.display()
-
Output:
Type: Car, Brand: Toyota, Model: Corolla 2022, Mileage: 15500 km
Type: Motorbike, Brand: Honda, Model: CD-70, Mileage: 8250 km
-
The class groups the data (attributes) and behaviour (methods). The constructor __init__ sets the initial values, and objects v1 and v2 are separate instances (encapsulation).
Q2. What is Functional Programming? Also write down two pros and two cons of Functional Programming. [Annual 2026 β Paper B] (1+2+2)
Answer:
Functional Programming (FP) is a programming paradigm in which programs are built by composing pure functions, functions that always give the same output for the same input and have no side effects. It uses immutable data, first-class and higher-order functions (map, filter, reduce), and recursion instead of loops. Examples are Haskell, Lisp, and functional features in Python.
squares = list(map(lambda x: x*x, [1, 2, 3])) # [1, 4, 9]
Pros
-
Fewer bugs and easier testing/debugging: pure functions with no side effects are predictable and can be tested independently.
-
Good for parallel/concurrent processing: immutable data avoids shared-state problems, and the code is concise and reusable.
Cons
-
Difficult to learn: recursion, immutability and higher-order functions are hard for beginners, and code may be less readable.
-
Performance and memory overhead: creating new copies of data instead of modifying it, and deep recursion, can be slower and use more memory. Handling I/O and state is awkward.
Q3. What is Object-Oriented Programming (OOP)? Also write down two pros and two cons of OOP. [Annual 2026 β Paper D] (1+2+2)
Answer:
Object-Oriented Programming (OOP) is a programming paradigm that organises software around objects: instances of classes that combine data (attributes) and behaviour (methods). Its main principles are encapsulation, abstraction, inheritance and polymorphism. Examples are Python, Java and C++.
Pros
-
Reusability: inheritance and classes let code be reused, which saves development time.
-
Modularity and easy maintenance: code is organised in self-contained objects, so it is easier to understand, debug, update and scale. Encapsulation also improves security of data.
Cons
-
More complex design: planning classes and relationships takes time and is harder for beginners; small programs may become unnecessarily large.
-
Performance overhead: objects use more memory, and method calls can make programs slower than procedural code.
You can find the other units of 2nd Year Computer Science on the main page: FBISE 2nd Year Computer Science short and long questions, all units.
Questions follow the FBISE HSSC-II Computer Science syllabus and paper pattern. Please confirm all dates and figures on the official website: www.fbise.edu.pk
Need help with 2nd Year Computer Science? Join our live online classes for the Federal Board. Book a free demo class.

Ask a question about this topic