Class 10 Computer Science Chapter 3 Complete Guide Book — Introduction to Python Programming | PunjabTest.com

Class 10 Computer Science Chapter 3 — Introduction to Python Programming
Home > PunjabTest.com > Class 10 > Computer Science — all chapters > Chapter 3: Introduction to Python Programming

اس chapter میں topics (Topics in this chapter)

Source note: This chapter is built from the existing PunjabTest.com library chapter for Class 10 Computer Science. No official book was available on disk for this build, so no book page numbers are claimed, and the exercise below is labelled SLO / board-pattern, as in the library chapter — it is not presented as the book's official exercise.

ماخذ نوٹ: یہ باب کلاس دہم کمپیوٹر سائنس کے موجودہ لائبریری باب سے بنایا گیا ہے۔ اس بلڈ کے لیے سرکاری کتاب ڈسک پر موجود نہیں تھی، اس لیے کتاب کے صفحہ نمبرز کا دعویٰ نہیں کیا گیا اور نیچے دی گئی مشق ایس ایل او / بورڈ پیٹرن کے طور پر لیبل کی گئی ہے — یہ کتاب کی سرکاری ایکسرسائز نہیں ہے۔

3.1 Why Python?پائتھون کیوں سیکھیں؟
🏷 Tags: Why Python?, Python
ENGLISH

Python is a popular, high-level programming language. High-level means it is written in words close to English, so humans can read it easily; the computer (through an interpreter) translates it into machine instructions step by step.

Python is popular because it is easy to read and write, free, works on Windows, Mac and Linux, and is used in real work: websites, data science, artificial intelligence, automation and games. Its simple syntax means beginners spend time learning thinking (solving problems) instead of fighting complicated grammar — which is why schools now teach Python before harder languages.

Interpreter vs compiler: A compiler translates a whole program before running it; Python's interpreter translates and runs one line at a time, so you can test a small piece of code immediately and see errors at once.

اردو

پائتھون ایک مقبول، ہائی لیول پروگرامنگ زبان ہے۔ ہائی لیول کا مطلب ہے کہ یہ انگریزی کے قریب الفاظ میں لکھی جاتی ہے، اس لیے انسان اسے آسانی سے پڑھ سکتے ہیں؛ کمپیوٹر (ایک انٹرپریٹر کے ذریعے) اسے مرحلہ بہ مرحلہ مشین ہدایات میں بدلتا ہے۔

پائتھون اس لیے مقبول ہے کہ یہ پڑھنے اور لکھنے میں آسان، مفت، ونڈوز، میک اور لینکس پر چلتی ہے اور حقیقی کام میں استعمال ہوتی ہے: ویب سائٹس، ڈیٹا سائنس، مصنوعی ذہانت، آٹومیشن اور گیمز۔ اس کی سادہ گرامر کا مطلب ہے کہ نئے سیکھنے والے پیچیدہ قواعد سے لڑنے کے بجائے سوچنے (مسائل حل کرنے) پر وقت لگاتے ہیں — اسی لیے اسکول اب مشکل زبانوں سے پہلے پائتھون پڑھاتے ہیں۔

انٹرپریٹر بمقابلہ کمپائلر: کمپائلر پورا پروگرام چلانے سے پہلے ترجمہ کرتا ہے؛ پائتھون کا انٹرپریٹر ایک وقت میں ایک لائن ترجمہ کر کے چلاتا ہے، اس لیے آپ کوڈ کا چھوٹا ٹکڑا فوراً آزما سکتے ہیں اور غلطی فوراً دیکھ سکتے ہیں۔

YOU write English-like code▼INTERPRETER reads line by line▼COMPUTER runs instructions▼OUTPUT appears on screen
Python کیوں seekhen سے سمجھو: Write code → interpreter → computer → output

کوڈ لکھیں → انٹرپریٹر → کمپیوٹر → آؤٹ پٹ
3.2 Your First Program: IDLE, print() and Commentsپہلا پروگرام: IDLE، print() اور کمنٹس
🏷 Tags: Your First Program: IDLE, print() and Comments
ENGLISH

IDLE is the simple editor that comes with Python. You type code in the editor, save the file with a .py name, and run it. The shell window shows the output and lets you test one line at a time.

print("Assalam-o-Alaikum")
print("I am learning Python")

print() displays text or values on the screen. Text must be inside quotes ("..." or '...'); numbers need no quotes: print(5 + 3) shows 8.

Comments are notes for humans that Python ignores. A single-line comment starts with #; a multi-line note uses triple quotes '''...'''. Good programs always explain tricky parts with comments.

اردو

IDLE وہ سادہ ایڈیٹر ہے جو پائتھون کے ساتھ آتا ہے۔ آپ ایڈیٹر میں کوڈ ٹائپ کرتے ہیں، فائل کو .py نام سے محفوظ کرتے ہیں اور چلاتے ہیں۔ شیل ونڈو آؤٹ پٹ دکھاتی ہے اور ایک وقت میں ایک لائن آزمانے دیتی ہے۔

print("Assalam-o-Alaikum")
print("I am learning Python")

print() اسکرین پر متن یا اقدار دکھاتا ہے۔ متن کوٹس ("..." یا '...') کے اندر ہونا چاہیے؛ اعداد کو کوٹس کی ضرورت نہیں: print(5 + 3) کا نتیجہ 8 ہوگا۔

کمنٹس انسانوں کے لیے نوٹس ہیں جنہیں پائتھون نظر انداز کرتا ہے۔ سنگل لائن کمنٹ # سے شروع ہوتا ہے؛ کئی لائنوں کا نوٹ ٹرپل کوٹس '''...''' سے لکھا جاتا ہے۔ اچھے پروگرام ہمیشہ مشکل حصوں کی وضاحت کمنٹس سے کرتے ہیں۔

OPEN IDLE editor▼TYPE print() code▼SAVE as .py file▼RUN and see output
Pehla program se samjho: Open IDLE → type → save .py → run

IDLE کھولیں → ٹائپ کریں → .py محفوظ کریں → چلائیں
3.3 Variables and Identifiersویری ایبلز اور آئیڈینٹیفائرز
🏷 Tags: Variables and Identifiers, variable
ENGLISH

Think of a variable as a labelled storage box in memory that holds information. A variable is created the moment you assign a value to it with =: a = 15 puts 15 in box a; name = "Aarosh" puts text in box name.

An identifier is simply a name you give to a program unit, such as a variable or function. Good identifiers make sense: user_age is good, x123 is confusing. Naming rules: use letters, digits and underscores; do not start with a digit; no spaces; do not use Python keywords (like print, if, for) as names; and remember names are case-sensitive — Name and name are different variables.

Python variables have no fixed type: the same name can later hold a different kind of value (planet = "Pluto" then planet = 9). The value has a type; the name is just a label.

اردو

ویری ایبل کو میموری میں لیبل والا اسٹوریج باکس سمجھیں جو معلومات رکھتا ہے۔ ویری ایبل اسی لمحے بنتا ہے جب آپ = سے اسے قدر دیتے ہیں: a = 15 باکس a میں 15 رکھتا ہے؛ name = "Aarosh" باکس name میں متن رکھتا ہے۔

آئیڈینٹیفائر محض وہ نام ہے جو آپ پروگرام کی کسی اکائی جیسے ویری ایبل یا فنکشن کو دیتے ہیں۔ اچھے آئیڈینٹیفائر بامعنی ہوتے ہیں: user_age اچھا ہے، x123 الجھن والا ہے۔ نام رکھنے کے قواعد: حروف، ہندسے اور انڈر اسکور استعمال کریں؛ ہندسے سے شروع نہ کریں؛ خالی جگہ نہ رکھیں؛ پائتھون کے کی ورڈز (جیسے print, if, for) کو نام نہ بنائیں؛ اور یاد رکھیں نام کیس سینسیٹو ہیں — Name اور name الگ ویری ایبلز ہیں۔

پائتھون ویری ایبلز کی کوئی مستقل قسم نہیں: وہی نام بعد میں مختلف قسم کی قدر رکھ سکتا ہے (planet = "Pluto" پھر planet = 9)۔ قسم قدر کی ہوتی ہے؛ نام صرف لیبل ہے۔

name → 'Aarosh' (text)▼age → 15 (number)▼marks → 87.5 (decimal)▼pass → True (yes/no)
Variables se samjho: Variable name → stored value

ویری ایبل کا نام → محفوظ شدہ قدر
3.4 Data Types: int, float, str, boolڈیٹا ٹائپس: int، float، str، bool
🏷 Tags: Data Types: int, float, str, bool
ENGLISH
TypeMeansExamples
int (integer)Whole numbers, no decimals-3, 0, 42, 1000
floatNumbers with decimals3.14, -0.5, 9.99
str (string)Text in quotes"hello", "Python@123"
bool (boolean)Only two values — note the capital letterTrue, False

Use type() to check a value's type: type(42) gives int. Strings are sequences of characters: "Ali"[0] is 'A' (counting starts at 0). You can join strings with + ("Ali" + " Khan" = "Ali Khan") and repeat with * ("Ha" * 3 = "HaHaHa").

Common beginner error: adding a number to text fails — "Age: " + 15 gives an error. Convert first: "Age: " + str(15) works.

اردو
قسممطلبمثالیں
intمکمل اعداد، بغیر اعشاریہ-3, 0, 42, 1000
floatاعشاریہ والے اعداد3.14, -0.5, 9.99
strکوٹس میں متن"hello", "Python@123"
boolصرف دو اقدار — بڑا حرف نوٹ کریںTrue, False

قدر کی قسم چیک کرنے کے لیے type() استعمال کریں: type(42) کا نتیجہ int ہے۔ اسٹرنگز حروف کی ترتیب ہیں: "Ali"[0] برابر 'A' ہے (گنتی 0 سے شروع ہوتی ہے)۔ اسٹرنگز کو + سے جوڑ سکتے ہیں ("Ali" + " Khan" = "Ali Khan") اور * سے دہرا سکتے ہیں ("Ha" * 3 = "HaHaHa")۔

عام ابتدائی غلطی: عدد کو متن سے جمع کرنا ناکام ہوتا ہے — "Age: " + 15 ایرر دے گا۔ پہلے تبدیل کریں: "Age: " + str(15) کام کرے گا۔

int: 42 (whole)▼float: 3.14 (decimal)▼str: 'hello' (text)▼bool: True / False
Data types se samjho: int, float, str, bool — the four basic types

int، float، str، bool — چار بنیادی اقسام
3.5 Operatorsآپریٹرز
🏷 Tags: Operators
ENGLISH
KindOperatorsExample → result
Arithmetic+ - * / // % **7 // 2 = 3, 7 % 2 = 1, 2 ** 3 = 8
Comparison== != > < >= <=5 > 3 → True
Logicaland or notTrue and False → False
Assignment= += -= *= /=x += 5 means x = x + 5

Watch out: = assigns a value, == compares two values — mixing them up is the most common beginner bug. Division / always gives a float (7 / 2 = 3.5), while floor division // drops the remainder (7 // 2 = 3) and % (modulus) gives only the remainder (7 % 2 = 1). Precedence: brackets first, then **, then * / // %, then + - — just like BODMAS in maths.

اردو
قسمآپریٹرزمثال → نتیجہ
ریاضیاتی+ - * / // % **7 // 2 = 3، 7 % 2 = 1، 2 ** 3 = 8
موازنہ== != > < >= <=5 > 3 → True
منطقیand or notTrue and False → False
اسائنمنٹ= += -= *= /=x += 5 کا مطلب x = x + 5 ہے

احتیاط: = قدر دیتا ہے، == دو اقدار کا موازنہ کرتا ہے — انہیں گڈ مڈ کرنا سب سے عام ابتدائی غلطی ہے۔ تقسیم / ہمیشہ float دیتی ہے (7 / 2 = 3.5)، جبکہ فلور ڈویژن // باقی چھوڑ دیتا ہے (7 // 2 = 3) اور % (ماڈولس) صرف باقی دیتا ہے (7 % 2 = 1)۔ ترجیح: پہلے بریکٹس، پھر **، پھر * / // %، پھر + - — بالکل ریاضی کے BODMAS کی طرح۔

ARITHMETIC: + - * / %▼COMPARISON: == != > <▼LOGICAL: and or not▼ASSIGNMENT: = += -=
Operators se samjho: Four operator families in Python

پائتھون میں آپریٹرز کی چار فیملیز
3.6 Input, Output and Type Conversionان پٹ، آؤٹ پٹ اور ٹائپ کنورژن
🏷 Tags: Input, Output and Type Conversion
ENGLISH

input() reads what the user types — but always as text (str), even if the user types digits. Convert it before doing maths:

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name, "— next year you will be", age + 1)

When the program runs, it pauses at input(), shows the prompt, and waits for the user to type something and press Enter. Conversion functions: int() (text/float → whole number), float() (→ decimal), str() (→ text). int("12") = 12, but int("12.5") fails — convert to float first.

Complete mini-program (rectangle area): length = float(input("Length: ")), width = float(input("Width: ")), print("Area =", length * width). Input → process → output: every program follows this pattern.

اردو

input() صارف جو ٹائپ کرتا ہے اسے پڑھتا ہے — لیکن ہمیشہ متن (str) کے طور پر، چاہے صارف ہندسے ہی کیوں نہ ٹائپ کرے۔ ریاضی سے پہلے اسے تبدیل کریں:

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name, "— next year you will be", age + 1)

جب پروگرام چلتا ہے تو وہ input() پر رکتا ہے، پرامپٹ دکھاتا ہے اور صارف کے کچھ ٹائپ کر کے Enter دبانے کا انتظار کرتا ہے۔ کنورژن فنکشنز: int() (متن/float → مکمل عدد)، float() (→ اعشاریہ)، str() (→ متن)۔ int("12") = 12 ہے، مگر int("12.5") ناکام ہوگا — پہلے float میں بدلیں۔

مکمل چھوٹا پروگرام (مستطیل کا رقبہ): length = float(input("Length: "))، width = float(input("Width: "))، print("Area =", length * width)۔ ان پٹ → پروسیس → آؤٹ پٹ: ہر پروگرام اسی پیٹرن پر چلتا ہے۔

INPUT: input() from user▼PROCESS: calculate / decide▼OUTPUT: print() to screen
Input aur output se samjho: Input → Process → Output (IPO)

ان پٹ → پروسیس → آؤٹ پٹ (IPO)
📝 SLO / Board-Pattern Questions — with Answersایس ایل او / بورڈ پیٹرن سوالات — جوابات کے ساتھ
SLO-BASED — NOT THE OFFICIAL EXERCISE

Book note (please read): This page follows the PCTB book Computer Science and Entrepreneurship, Class 10 (session 2026–27). The chapter titles and section order were verified against current 2026–27 Punjab listings and the board syllabus for this book. The book PDF itself could not be opened page-by-page during this build, so the questions below are SLO / board-pattern questions written for this chapter — they are NOT presented as the book's official exercise. Where a point was not confirmed from the book, it is kept general and no invented fact is stated as a book fact.

ایس ایل او پر مبنی

کتاب کے بارے میں نوٹ: یہ صفحہ پی سی ٹی بی کی کتاب کمپیوٹر سائنس اینڈ انٹرپرینیورشپ، جماعت دہم (سیشن 2026–27) کے مطابق ہے۔ باب کے عنوانات اور ترتیب موجودہ 2026–27 کی پنجاب لسٹنگز اور بورڈ سلیبس سے تصدیق شدہ ہیں۔ کتاب کا پی ڈی ایف اس بلڈ کے دوران صفحہ بہ صفحہ نہیں کھولا جا سکا، اس لیے نیچے دیے گئے سوالات ایس ایل او / بورڈ پیٹرن کے سوالات ہیں — یہ کتاب کی سرکاری ایکسرسائز نہیں ہیں۔

Section 1: Multiple Choice Questionsحصہ 1: کثیر الانتخابی سوالات
1. Python is a:

Answer: (b) High-level language — written in English-like words, translated by an interpreter.

2. What does print(5 + 3) display?

Answer: (c) 8 — numbers need no quotes, so 5 + 3 is calculated.

3. Which is a valid Python variable name?

Answer: (b) user_age — names cannot start with a digit, contain spaces, or be keywords like 'for'.

4. type(3.14) gives:

Answer: (b) float — numbers with decimals are floats.

5. What is 7 % 2 in Python?

Answer: (c) 1 — % (modulus) gives the remainder of 7 ÷ 2.

6. input() always returns a value of type:

Answer: (c) str — even typed digits arrive as text and must be converted with int() or float() before maths.

7. Which symbol starts a single-line comment in Python?

Answer: (b) # — everything after # on that line is ignored by Python.

8. x = 10; x += 5 makes x equal to:

Answer: (c) 15 — x += 5 means x = x + 5.

Section 2: Short Questionsحصہ 2: مختصر سوالات
1. Define Python and state two reasons it is popular for beginners.

Answer: Python is a popular high-level programming language. It is popular because its English-like syntax is easy to read and write, and because it is free and used in real fields like websites, data science and AI.

2. Differentiate between compiler and interpreter.

Answer: A compiler translates the whole program before running it. An interpreter (used by Python) translates and runs one line at a time, so small pieces can be tested immediately and errors appear at once.

3. What are the rules for naming variables in Python?

Answer: Use letters, digits and underscores; do not start with a digit; no spaces; do not use Python keywords as names; names are case-sensitive (Name and name differ).

4. Why does "Age: " + 15 cause an error, and how do you fix it?

Answer: Because Python cannot add text (str) and a number (int). Fix by converting: "Age: " + str(15).

5. What does input() return? Show how to read an age as a number.

Answer: input() always returns text (str). To read an age as a number: age = int(input("Enter your age: ")).

Section 3: Long Questionsحصہ 3: تفصیلی سوالات
1. Write a Python program that takes length and width from the user and prints the area of a rectangle. Explain each line.

Answer: length = float(input("Length: ")) — reads length as text, converts to float. width = float(input("Width: ")) — same for width. print("Area =", length * width) — multiplies and displays the result. This follows Input → Process → Output: input() gathers data, * processes it, print() shows it.

2. Explain the four basic data types in Python with examples and one common error for each type family.

Answer: int: whole numbers e.g. 42; float: decimals e.g. 3.14; str: text in quotes e.g. "hello"; bool: True/False (capital first letter). Common errors: using quotes around numbers when maths is needed ("5" + "3" = "53", not 8); forgetting capital T/F in True/False; adding str and int without str() conversion.

3. Explain operators in Python: arithmetic, comparison, logical and assignment, with examples.

Answer: Arithmetic (+ - * / // % **): 7 // 2 = 3, 7 % 2 = 1, 2 ** 3 = 8. Comparison (== != > < >= <=): 5 > 3 is True; note == compares while = assigns. Logical (and or not): True and False is False. Assignment (= += -=): x += 5 means x = x + 5. Precedence follows brackets, **, then * / // %, then + -, like BODMAS.

📌 باب کا خلاصہ اور رہنمائی — اس باب میں کیا ہے؟

This chapter introduces Python programming: why Python is a good first language, how to write and run your first program in IDLE, how variables store values, the four basic data types, the operators for maths and comparison, and how input, output and type conversion turn a typed value into a working program.

Revision guidance: Revision guidance: type every small program yourself in IDLE — reading is not enough. Test print(), one variable, one input with int() conversion, and one % calculation, and say what type each value has before you run it.

یہ باب پائتھون پروگرامنگ کا تعارف ہے: پائتھون پہلی زبان کے طور پر کیوں اچھی ہے، IDLE میں پہلا پروگرام کیسے لکھیں اور چلائیں، ویری ایبلز قدریں کیسے محفوظ کرتے ہیں، چار بنیادی ڈیٹا ٹائپس، ریاضی اور موازنے کے آپریٹرز، اور ان پٹ، آؤٹ پٹ اور ٹائپ کنورژن ٹائپ شدہ قدر کو چلتا ہوا پروگرام کیسے بناتے ہیں۔

نظرثانی کی رہنمائی: نظرثانی کی رہنمائی: ہر چھوٹا پروگرام خود IDLE میں ٹائپ کرو — صرف پڑھنا کافی نہیں۔ print()، ایک variable، int() کنورژن کے ساتھ ایک input، اور ایک % حساب آزماؤ، اور چلانے سے پہلے بتاؤ کہ ہر قدر کی type کیا ہے۔

🎯 مزید MCQs اور Tests کے لیے

Chapter-wise tests, fresh random papers اور instant score کے لیے PunjabTest.com کا میں test section دیکھو:

PunjabTest.com — Tests →

PunjabTest.com — Complete Guide Book • Class 10 Computer Science, Chapter 3 (Session 2026–27) • English + Urdu

← Chapter 2Chapter 4 →