© 2026 schoolict.net (Ruwan Mangala Suraweera)
9.7 Python Basics: Structure, Variables, Data Types, Operators and I/OPython මූලික: ව්යුහය, විචල්ය, දත්ත වර්ග, කාරක සහ ආදාන/ප්රතිදාන
Grade 13 A/L ICT · Lesson 913 ශ්රේණිය A/L ICT · පාඩම 9
In this videoමේ වීඩියෝවේ
- Comments start with #.විවරණ # වලින් ආරම්භ වේ.
- int, float, str and bool are primitive types.int, float, str, bool ප්රාථමික වර්ග ය.
- input() returns a string – convert it.input() str දෙයි – හරවන්න.
- ** before * / // % before + −.** පසු * / // %, පසු + −.
- · is XOR; ** is power.· XOR; ** බලය.
Notesසටහන්
Syllabus 9.7. Here we use an imperative language – Python – to encode algorithms. You meet the structure of a program, comments, constants and variables, the primitive data types, arithmetic, relational, logical and bitwise operators, operator precedence, keyboard input and screen output.විෂය නිර්දේශය 9.7. ඇල්ගොරිතම කේතනයට අනුඥාත්මක භාෂාවක් – Python – භාවිත කරමු. වැඩසටහනක ව්යුහය, විවරණ, නියත සහ විචල්ය, ප්රාථමික දත්ත වර්ග, අංක ගණිත, සම්බන්ධතා, තාර්කික සහ bitwise කාරක, කාරක ප්රමුඛතාව, යතුරුපුවරු ආදානය සහ තිර ප්රතිදානය හඳුනා ගනිමු.
1. Structure, comments, constants and variables1. ව්යුහය, විවරණ, නියත සහ විචල්ය
🐍 Constants, variables, types and inputනියත, විචල්ය, වර්ග සහ ආදානය
RATE = 0.08 # constant (by convention UPPER CASE) name = input("Name: ") # str qty = int(input("Quantity: ")) # int price = 250.0 # float paid = True # bool total = qty * price * (1 + RATE) print(name, "pays Rs.", round(total, 2)) print(type(qty).__name__, type(price).__name__, type(paid).__name__)
▶ Outputප්රතිදානය (input: Nimal 4)(ආදානය: Nimal 4)
Name: Nimal Quantity: 4 Nimal pays Rs. 1080.0 int float bool
| Typeවර්ගය | Exampleඋදාහරණය | Meaningඅර්ථය |
|---|---|---|
| intint | 44 | Whole numberපූර්ණ සංඛ්යාව |
| floatfloat | 250.0250.0 | Real (decimal) numberදශම සංඛ්යාව |
| strstr | “Nimal”“Nimal” | Textපෙළ |
| boolbool | True / FalseTrue / False | Truth valueසත්ය අගය |
A comment starts with # and is ignored by the translator. A variable is a named memory location whose value can change; a constant (written in UPPER CASE by convention) should not change. input() always returns a str, so int() or float() converts it.විවරණය # වලින් ආරම්භ වී පරිවර්තකය නොසලකයි. විචල්යය අගය වෙනස් විය හැකි නම් කළ මතක ස්ථානයකි; නියතය (සම්ප්රදායට UPPER CASE) වෙනස් නොවිය යුතුය. input() සැමවිටම str ලබා දෙන නිසා int() හෝ float() මගින් හරවයි.
4 × 250.0 = 1000.0; × 1.08 = 1080.0, so it prints “Nimal pays Rs. 1080.0”. type() shows int, float, bool.4 × 250.0 = 1000.0; × 1.08 = 1080.0. type() int, float, bool පෙන්වයි.
2. Operators and precedence2. කාරක සහ ප්රමුඛතාව
| Categoryකාණ්ඩය | Operatorsකාරක | Example → resultඋදාහරණය → ප්රතිඵලය |
|---|---|---|
| Arithmeticඅංක ගණිත | + – * / // % **+ – * / // % ** | 7 // 2 → 3, 7 % 2 → 1, 7 / 2 → 3.57 // 2 → 3, 7 % 2 → 1, 7 / 2 → 3.5 |
| Relationalසම්බන්ධතා | == != < <= > >=== != < <= > >= | 5 > 3 → True5 > 3 → True |
| Logicalතාර්කික | and or notand or not | 5 > 3 and 2 > 8 → False5 > 3 and 2 > 8 → False |
| BitwiseBitwise | & | · ~ << >>& | · ~ << >> | 5 & 3 → 1, 5 | 3 → 7, 5 · 3 → 6, 5 << 1 → 105 & 3 → 1, 5 | 3 → 7, 5 · 3 → 6, 5 << 1 → 10 |
🐍 Operators and precedenceකාරක සහ ප්රමුඛතාව
print(7 // 2, 7 % 2, 7 / 2) # arithmetic print(3 + 4 * 2, (3 + 4) * 2) # precedence print(2 ** 3 ** 2) # ** is right to left print(10 - 4 - 3) # - is left to right print(5 > 3 and 2 > 8) # relational + logical print(not True or True) print(5 & 3, 5 | 3, 5 · 3, 5 << 1) # bitwise
▶ Outputප්රතිදානය
3 1 3.5 11 14 512 3 False True 1 7 6 10
groups right to left: 3 2 = 9, then 2 9 = 512. 5 = 101 and 3 = 011 in binary; XOR gives 110 = 6**. දකුණේ සිට වමට: 3 2 = 9, 2 9 = 512. 101 XOR 011 = 110 = 6**.
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1What does input() return?input() ලබා දෙන්නේ?
27 // 2 and 7 % 2?7 // 2 සහ 7 % 2?
33 + 4 * 2?3 + 4 * 2?
4Value of 10 – 4 – 3?10 – 4 – 3?
5Four primitive types?ප්රාථමික වර්ග හතර?
6Constant vs variable?නියතය සහ විචල්යය?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
17 // 2 in Python gives7 // 2
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Floor division.floor බෙදීම.
27 % 2 in Python gives7 % 2
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Remainder.ශේෂය.
33 + 4 * 2 gives3 + 4 * 2
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
* first.* මුලින්.
42 3 2 gives2 3 2
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Right to left.දකුණේ සිට.
55 · 3 in Python gives5 · 3
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
XOR.XOR.
6not True or True givesnot True or True
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
not first.not මුලින්.
7The type of the value returned by input() isinput()
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Always str.සැමවිටම str.
8Nimal’s total with 8% tax on 4 × 250.0 isඑකතුව
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
1000 × 1.08.1000 × 1.08.
9Which term means: “Note in code starting with # that is not executed”?“ධාවනය නොවන # වලින් ආරම්භ වන සටහන” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Comment – Note in code starting with # that is not executed.විවරණය – ධාවනය නොවන # වලින් ආරම්භ වන සටහන.
10Which term means: “Named storage location whose value can change”?“අගය වෙනස් විය හැකි නම් කළ ගබඩා ස්ථානය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Variable – Named storage location whose value can change.විචල්යය – අගය වෙනස් විය හැකි නම් කළ ගබඩා ස්ථානය.
11Which term means: “Named value that should not change while running”?“ධාවනයේදී වෙනස් නොවිය යුතු නම් කළ අගය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Constant – Named value that should not change while running.නියතය – ධාවනයේදී වෙනස් නොවිය යුතු නම් කළ අගය.
12Which term means: “Basic built-in type such as int, float, str or bool”?“int, float, str, bool වැනි මූලික වර්ගය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Primitive data type – Basic built-in type such as int, float, str or bool.ප්රාථමික දත්ත වර්ගය – int, float, str, bool වැනි මූලික වර්ගය.
13Which term means: “Whole number type int”?“int පූර්ණ සංඛ්යා වර්ගය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Integer – Whole number type int.පූර්ණ සංඛ්යාව – int පූර්ණ සංඛ්යා වර්ගය.
14Which term means: “Number type with a decimal part”?“දශම කොටසක් ඇති සංඛ්යා වර්ගය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Float – Number type with a decimal part.Float – දශම කොටසක් ඇති සංඛ්යා වර්ගය.
15Which term means: “Type holding True or False”?“True හෝ False රඳවන වර්ගය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Boolean – Type holding True or False.Boolean – True හෝ False රඳවන වර්ගය.
16Which term means: “Operator such as + or // that calculates numbers”?“සංඛ්යා ගණනය කරන + හෝ // වැනි කාරකය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Arithmetic operator – Operator such as + or // that calculates numbers.අංක ගණිත කාරකය – සංඛ්යා ගණනය කරන + හෝ // වැනි කාරකය.
17Which term means: “Operator that compares values and gives True or False”?“අගයන් සසඳා True/False දෙන කාරකය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Relational operator – Operator that compares values and gives True or False.සම්බන්ධතා කාරකය – අගයන් සසඳා True/False දෙන කාරකය.
18Which term means: “and, or, not combining conditions”?“කොන්දේසි එක් කරන and, or, not” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Logical operator – and, or, not combining conditions.තාර්කික කාරකය – කොන්දේසි එක් කරන and, or, not.
19Which term means: “Operator working on individual bits such as & or ·”?“& හෝ · වැනි bits මත ක්රියා කරන කාරකය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Bitwise operator – Operator working on individual bits such as & or ·.Bitwise කාරකය – & හෝ · වැනි bits මත ක්රියා කරන කාරකය.
20Which term means: “Order in which operators are evaluated”?“කාරක ගණනය කරන පිළිවෙළ” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Operator precedence – Order in which operators are evaluated.කාරක ප්රමුඛතාව – කාරක ගණනය කරන පිළිවෙළ.
MCQ answer keyMCQ පිළිතුරු
- D – Floor division.floor බෙදීම.
- A – Remainder.ශේෂය.
- B – * first.* මුලින්.
- C – Right to left.දකුණේ සිට.
- A – XOR.XOR.
- D – not first.not මුලින්.
- E – Always str.සැමවිටම str.
- C – 1000 × 1.08.1000 × 1.08.
- B – Comment – Note in code starting with # that is not executed.විවරණය – ධාවනය නොවන # වලින් ආරම්භ වන සටහන.
- C – Variable – Named storage location whose value can change.විචල්යය – අගය වෙනස් විය හැකි නම් කළ ගබඩා ස්ථානය.
- D – Constant – Named value that should not change while running.නියතය – ධාවනයේදී වෙනස් නොවිය යුතු නම් කළ අගය.
- E – Primitive data type – Basic built-in type such as int, float, str or bool.ප්රාථමික දත්ත වර්ගය – int, float, str, bool වැනි මූලික වර්ගය.
- B – Integer – Whole number type int.පූර්ණ සංඛ්යාව – int පූර්ණ සංඛ්යා වර්ගය.
- E – Float – Number type with a decimal part.Float – දශම කොටසක් ඇති සංඛ්යා වර්ගය.
- B – Boolean – Type holding True or False.Boolean – True හෝ False රඳවන වර්ගය.
- A – Arithmetic operator – Operator such as + or // that calculates numbers.අංක ගණිත කාරකය – සංඛ්යා ගණනය කරන + හෝ // වැනි කාරකය.
- D – Relational operator – Operator that compares values and gives True or False.සම්බන්ධතා කාරකය – අගයන් සසඳා True/False දෙන කාරකය.
- A – Logical operator – and, or, not combining conditions.තාර්කික කාරකය – කොන්දේසි එක් කරන and, or, not.
- C – Bitwise operator – Operator working on individual bits such as & or ·.Bitwise කාරකය – & හෝ · වැනි bits මත ක්රියා කරන කාරකය.
- E – Operator precedence – Order in which operators are evaluated.කාරක ප්රමුඛතාව – කාරක ගණනය කරන පිළිවෙළ.
Structured Questionsව්යුහගත ප්රශ්න
1Name four primitive data types with examples.ප්රාථමික වර්ග. (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2Explain variable, constant and comment with code.විචල්ය, නියත, විවරණ. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Evaluate 3 + 4 * 2, (3 + 4) * 2 and 2 3 2 and explain.ගණනය කරන්න. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
4Give one example each of relational, logical and bitwise operators with results.කාරක තුන. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Write a program that inputs quantity and prints the total with 8% tax.8% බදු වැඩසටහන. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- Comments start with #.විවරණ # වලින් ආරම්භ වේ.
- int, float, str and bool are primitive types.int, float, str, bool ප්රාථමික වර්ග ය.
- input() returns a string – convert it.input() str දෙයි – හරවන්න.
- ** before * / // % before + −.** පසු * / // %, පසු + −.
- · is XOR; ** is power.· XOR; ** බලය.
Downloadsබාගත කිරීම්
Resource Book Lesson Note Download Questions Syllabus Sinhala LMS Simulator Tool
