National Digital LMS
Module 3: Core Competencies

Chapter 5: Inventory Valuation Methods

Periodic vs perpetual systems, FIFO (First-In, First-Out), LIFO, and Weighted Average Cost.

20 mins read Pages 77 - 95
Bilingual Learning (English & اردو) Class 12 / HSSC-II Level

Chapter 5: Code Testing and Debugging (Page 60 – 71)

پانچواں باب: کوڈ ٹیسٹنگ اور ڈی بگنگ

Writing software is an iterative process where identifying, preventing, and fixing defects is paramount. This chapter categorizes software errors (Syntax, Runtime Exceptions, Logical), covers defensive programming architectures using Python try-except-finally blocks, explores software testing levels (Unit, Integration, System, Acceptance), contrasts Black-box and White-box testing, and outlines systematic debugging techniques.

کوئی بھی سافٹ ویئر بناتے وقت غلطیوں کا ہونا فطری عمل ہے۔ اس باب میں پروگرام کی غلطیوں کی اقسام، پائتھن میں ایکسیپشن ہینڈلنگ کے ذریعے سافٹ ویئر کو کریش ہونے سے بچانا (`try-except`)، یونٹ ٹیسٹنگ، بلیک باکس اور وائٹ باکس ٹیسٹنگ اور خرابیوں کو دور کرنے کی تکنیکیں سکھائی گئی ہیں۔
Comprehensive Textbook Learning Material (تفصیلی تعلیمی مواد)
Full Syllabus Coverage • BISE Punjab
1 1. Software Defect Classification: Syntax, Runtime & Logical
۱. پروگرام کی غلطیوں کی اقسام (Syntax, Runtime, Logical)
English Theoretical Concept & Technical Breakdown:
1. **Syntax Errors:** Violations of Python's grammar rules. Detected during compilation/parsing before any code executes. Examples: missing closing parenthesis `)` or typing `prnt("Hi")`.
2. **Runtime Errors (Exceptions):** The code grammar is completely valid, but an impossible operation occurs while the program is actively executing, triggering a crash. Examples: dividing by zero (`ZeroDivisionError`), accessing a non-existent list index (`IndexError`), or opening an absent file (`FileNotFoundError`).
3. **Logical Errors (Semantic Bugs):** The program compiles and executes without crashing or throwing errors, but computes mathematically or logically incorrect results because the programmer's logic was flawed. Examples: calculating average as `total / 10` instead of `total / count`, or using `<` instead of `<=`.
آسان اردو میں مکمل اور تفصیلی وضاحت:
۱. **سنٹیکس ایرر (Syntax Error):** زبان کے گرامر اور قوانین کی خلاف ورزی (جیسے کولن `:` بھول جانا یا بریکٹ بند نہ کرنا)۔ کمپیوٹر کوڈ چلنے سے پہلے ہی اسے پکڑ لیتا ہے۔
۲. **رن ٹائم ایرر (Runtime Exception):** کوڈ چلتے ہوئے اچانک کسی غیر قانونی کام پر کریش ہو جانا (جیسے صفر سے تقسیم کرنا، یا لسٹ میں ۵ چیزیں ہوں اور آپ چھٹی مانگ رہے ہوں)۔
۳. **لاجیکل ایرر (Logical Bug):** پروگرام بغیر کسی ایرر یا رکاوٹ کے چلتا ہے، لیکن جواب غلط دیتا ہے کیونکہ پروگرامر کی منطق غلط تھی۔ مثلاً رقبہ نکالتے وقت لمبائی کو چوڑائی سے ضرب دینے کے بجائے جمع کر دینا۔
Real-World Student Analogy (روزمرہ زندگی سے آسان فہم مثال):
In English: Syntax error is writing "catt" instead of "cat". Runtime error is driving along and hitting an unexpected deep ditch that breaks your tire. Logical error is successfully driving 100 miles on the wrong motorway heading towards Karachi when you needed to go to Peshawar.
سنٹیکس ایرر املا کی غلطی ہے۔ رن ٹائم ایرر گاڑی کا ایندھن اچانک ختم ہو جانا ہے۔ لاجیکل ایرر پشاور جانے کے بجائے غلط سڑک پر گاڑی چلا کر کراچی کی طرف نکل جانا ہے۔
BISE Punjab Board Examination Tip (اہم امتحانی نکات):
Exam Favorite Question: "Why are logical errors considered the most dangerous and difficult to detect?" (Because compilers cannot spot them; only rigorous test cases reveal incorrect output).
2 2. Defensive Programming with `try-except-else-finally`
۲. پائتھن میں ایکسیپشن ہینڈلنگ (`try-except`) کی مکمل ساخت
English Theoretical Concept & Technical Breakdown:
Python provides robust structured exception handling to prevent unexpected crashes:
```python
try:
# 1. Risky code that might throw an exception
numerator = 100
denominator = int(input("Enter divisor: "))
result = numerator / denominator
except ZeroDivisionError:
# 2. Executed ONLY if division by zero occurs
print("Handled: Cannot divide by zero!")
except ValueError:
# 3. Executed if user types non-numeric text
print("Handled: Please enter integer digits only!")
else:
# 4. Executed ONLY if NO exceptions occurred
print(f"Success! Result = {result}")
finally:
# 5. ALWAYS executed, regardless of whether an error occurred
print("Cleanup: Database connections closed.")
```
آسان اردو میں مکمل اور تفصیلی وضاحت:
پروگرام کو کریش ہونے سے بچانے کے لیے پائتھن چار کلیدی الفاظ فراہم کرتا ہے:
- `try`: وہ کوڈ جس میں خرابی پیدا ہونے کا خطرہ ہو۔
- `except`: اگر خرابی آئے تو یہ بلاک اسے پکڑ کر سنبھالتا ہے اور صارف کو پیار سے غلطی سمجھاتا ہے۔
- `else`: اگر کوڈ بغیر کسی خرابی کے کامیابی سے چل جائے تو یہ حصہ چلتا ہے۔
- `finally`: چاہے خرابی آئے یا نہ آئے، یہ حصہ ہر حالت میں چلتا ہے تاکہ کھلی فائلیں یا نیٹ ورک کنکشن محفوظ بند ہو سکیں۔
Real-World Student Analogy (روزمرہ زندگی سے آسان فہم مثال):
In English: `try` is walking across a tightrope. `except` is the safety net that catches you if you fall so you don't die. `finally` is packing up the circus tent when the show ends.
`try` رسی پر چلنا ہے۔ `except` وہ حفاظتی جالی ہے جو گرنے کی صورت میں چوٹ لگنے سے بچاتی ہے۔ اور `finally` شو ختم ہونے پر سامان سمیٹنا ہے۔
BISE Punjab Board Examination Tip (اہم امتحانی نکات):
Short Question: Explain the role of the finally block in Python exception handling.
3 3. Testing Levels & Black-Box vs. White-Box Testing
۳. ٹیسٹنگ کے درجات اور بلیک باکس بمقابلہ وائٹ باکس
English Theoretical Concept & Technical Breakdown:
- **Unit Testing:** Testing individual isolated functions or methods to ensure they return expected outputs for given boundary inputs.
- **Integration Testing:** Combining independently tested modules to verify data interfaces correctly between them.
- **System Testing:** Testing the complete, end-to-end assembled software across diverse environments.
- **Black-Box Testing (Functional):** The tester has zero visibility into the internal source code. They provide inputs and verify whether outputs match the requirements specification.
- **White-Box Testing (Structural):** The tester has complete visibility into internal algorithms, inspecting branch paths, loops, and conditions to ensure 100% code coverage.
آسان اردو میں مکمل اور تفصیلی وضاحت:
- **یونٹ ٹیسٹنگ (Unit Testing):** پورے سافٹ ویئر کے بجائے کسی ایک چھوٹے فنکشن کو تنہائی میں چیک کرنا۔
- **انٹیگریشن ٹیسٹنگ (Integration Testing):** الگ الگ بنے ماڈیولز کو جوڑ کر باہمی رابطے کی جانچ کرنا۔
- **بلیک باکس ٹیسٹنگ (Black-Box):** ٹیسٹر کوڈ کو اندر سے نہیں دیکھتا؛ وہ صرف ان پٹ دیتا ہے اور چیک کرتا ہے کہ مطلوبہ آؤٹ پٹ آیا یا نہیں۔
- **وائٹ باکس ٹیسٹنگ (White-Box):** ٹیسٹر کوڈ کی ہر لائن، ہر لوپ اور ہر شاخ کو اندر سے دیکھ کر باریکی سے چیک کرتا ہے۔
Real-World Student Analogy (روزمرہ زندگی سے آسان فہم مثال):
In English: Black-box is taking a car on a test drive to see if it turns and accelerates smoothly. White-box is an engineer taking the engine apart to inspect every gear and spark plug.
بلیک باکس گاڑی کو چلا کر دیکھنا ہے کہ وہ صحیح بھاگ رہی ہے یا نہیں۔ وائٹ باکس مکینک کا انجن کھول کر اندرونی پرزے باریکی سے چیک کرنا ہے۔
BISE Punjab Board Examination Tip (اہم امتحانی نکات):
Tabular comparison: Differentiate between Black-box and White-box testing.
Looking for the official textbook pages?

Jump directly to pages 77 - 95 in the embedded streaming viewer.

PCTB Official Textbook - Chapter 5 Start Page: 77
Download
Protected Stream Proxy: Direct hotlinking is blocked. Byte-ranges are streamed dynamically.
Class 12 Chapters