© 2026 schoolict.net (Ruwan Mangala Suraweera)
1.10 Sub-programs: Functions and Proceduresඋප වැඩසටහන්: ශ්රිත සහ ක්රියා පටිපාටි
G.C.E. O/L Grade 11 ICT · Lesson 1G.C.E. O/L ICT · 11 ශ්රේණිය · පාඩම 1
In this videoමේ වීඩියෝවේ
- A sub-program does one named job.උප වැඩසටහනක් නමක් ඇති එක් කාර්යයක් කරයි.
- Benefits: reusability, readability, maintainability.වාසි: නැවත භාවිතය, කියවීමේ පහසුව, නඩත්තුව.
- Function returns a value.ශ්රිතය අගයක් ආපසු දෙයි.
- Procedure returns no value.ක්රියා පටිපාටිය අගයක් ආපසු නොදෙයි.
- Parameters receive arguments.පරාමිති තර්ක ලබා ගනී.
Notesසටහන්
Syllabus 10.10. A sub-program is a small, named part of a program that does one job. We write it once and call (use) it whenever we need it – like a recipe for pol sambol that you can follow every day without rewriting it. Big programs are built from many small sub-programs.විෂය නිර්දේශය 10.10. උප වැඩසටහනක් යනු එක් කාර්යයක් කරන, නමක් ඇති වැඩසටහනක කුඩා කොටසකි. අප එය එක් වරක් ලියා අවශ්ය සෑම විටම කැඳවමු (භාවිත කරමු) – නැවත නොලියා දිනපතා අනුගමනය කළ හැකි පොල් සම්බෝල වට්ටෝරුවක් මෙන්. විශාල වැඩසටහන් කුඩා උප වැඩසටහන් බොහොමයකින් සාදා ඇත.
1. Why use sub-programs?1. උප වැඩසටහන් භාවිත කරන්නේ ඇයි?
2. Two kinds of sub-programs2. උප වැඩසටහන් වර්ග දෙක
| Value-returningඅගයක් ආපසු දෙන | Non-value-returningඅගයක් ආපසු නොදෙන | |
|---|---|---|
| Pascal namePascal නම | functionfunction | procedureprocedure |
| PythonPython | def … with return valuereturn අගයක් සහිත def | def … without return valuereturn අගයක් නැති def |
| Gives backආපසු දෙන්නේ | one value (e.g. a grade)එක් අගයක් (උදා ශ්රේණියක්) | nothing – it just does a jobකිසිවක් නැත – කාර්යයක් පමණක් කරයි |
| Exampleඋදාහරණය | GetGrade(82) → ‘A’GetGrade(82) → ‘A’ | PrintLinePrintLine |
3. Parameters and arguments3. පරාමිති සහ තර්ක
Values we send into a sub-program are parameters. In area(length, width), length and width are parameters. When we call area(5, 4), the values 5 and 4 are the arguments.උප වැඩසටහනකට යවන අගයන් පරාමිති (parameters) වේ. area(length, width) හි length සහ width පරාමිති වේ. area(5, 4) කැඳවන විට 5 සහ 4 අගයන් තර්ක (arguments) වේ.
4. A value-returning function4. අගයක් ආපසු දෙන ශ්රිතයක්
GetGrade receives a mark and returns a grade letter, using the O/L grade limits (A 75, B 65, C 50, S 35).GetGrade ලකුණක් ලබාගෙන O/L ශ්රේණි සීමා (A 75, B 65, C 50, S 35) භාවිතයෙන් ශ්රේණි අකුරක් ආපසු දෙයි.
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
FUNCTION GetGrade(Marks) IF Marks >= 75 THEN RETURN "A" ELSE IF Marks >= 65 THEN RETURN "B" ELSE IF Marks >= 50 THEN RETURN "C" ELSE IF Marks >= 35 THEN RETURN "S" ELSE RETURN "W" ENDIF ENDFUNCTION BEGIN FOR k = 1 TO 3 INPUT M DISPLAY GetGrade(M) ENDFOR END
program GradeFunction; var k, m: integer; function GetGrade(marks: integer): char; begin if marks >= 75 then GetGrade := 'A' else if marks >= 65 then GetGrade := 'B' else if marks >= 50 then GetGrade := 'C' else if marks >= 35 then GetGrade := 'S' else GetGrade := 'W'; end; begin for k := 1 to 3 do begin write('Enter mark: '); readln(m); writeln('Grade: ', GetGrade(m)); end; end.
def get_grade(marks): if marks >= 75: return "A" elif marks >= 65: return "B" elif marks >= 50: return "C" elif marks >= 35: return "S" else: return "W" for k in range(3): m = int(input("Enter mark: ")) print("Grade:", get_grade(m))
▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter mark: 82 Grade: A Enter mark: 47 Grade: S Enter mark: 66 Grade: B
5. Procedures (non-value-returning)5. ක්රියා පටිපාටි (අගයක් ආපසු නොදෙන)
A shop bill uses PrintLine three times and ShowItem for each item. PrintLine has no parameters; ShowItem has three.සාප්පු බිල්පතක PrintLine තුන් වරක් ද එක් එක් අයිතමය සඳහා ShowItem ද භාවිත කරයි. PrintLine ට පරාමිති නැත; ShowItem ට තුනක් ඇත.
program BillProcedures; procedure PrintLine; begin writeln('------------------------'); end; procedure ShowItem(item: string; price, qty: integer); begin writeln(item, ': Rs. ', price * qty); end; begin PrintLine; writeln('SAMPLE SHOP BILL'); PrintLine; ShowItem('Bread', 120, 2); ShowItem('Milk packet', 280, 1); ShowItem('Eggs', 55, 6); PrintLine; end.
def print_line(): print("-" * 24) def show_item(item, price, qty): print(item + ": Rs.", price * qty) print_line() print("SAMPLE SHOP BILL") print_line() show_item("Bread", 120, 2) show_item("Milk packet", 280, 1) show_item("Eggs", 55, 6) print_line()
▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්රතිදානය
------------------------ SAMPLE SHOP BILL ------------------------ Bread: Rs. 240 Milk packet: Rs. 280 Eggs: Rs. 330 ------------------------
6. Calling a function many times6. ශ්රිතයක් බොහෝ වර කැඳවීම
A function can be used inside an expression, just like a number.ශ්රිතයක් සංඛ්යාවක් මෙන්ම ප්රකාශනයක් තුළ භාවිත කළ හැක.
program RectArea; function Area(length, width: integer): integer; begin Area := length * width; end; begin writeln('Room 1 = ', Area(5, 4)); writeln('Room 2 = ', Area(6, 3)); writeln('Both = ', Area(5, 4) + Area(6, 3)); end.
def area(length, width): return length * width print("Room 1 =", area(5, 4)) print("Room 2 =", area(6, 3)) print("Both =", area(5, 4) + area(6, 3))
▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්රතිදානය
Room 1 = 20 Room 2 = 18 Both = 38
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1What is a sub-program?උප වැඩසටහනක් යනු කුමක්ද?
2Give three advantages of sub-programs.උප වැඩසටහන්වල වාසි තුනක් දෙන්න.
3Difference between a function and a procedure?ශ්රිතයක් සහ ක්රියා පටිපාටියක් අතර වෙනස?
4What is GetGrade(66)?GetGrade(66) කුමක්ද?
5What does area(6, 3) return?area(6, 3) ආපසු දෙන්නේ කුමක්ද?
6In area(5, 4), what are 5 and 4?area(5, 4) හි 5 සහ 4 යනු මොනවාද?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
1A named part of a program that does one job is a…එක් කාර්යයක් කරන නමක් ඇති වැඩසටහන් කොටසක්…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Sub-program.උප වැඩසටහන.
2A sub-program that returns a value is a…අගයක් ආපසු දෙන උප වැඩසටහනක්…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Function.ශ්රිතය.
3In Pascal, a sub-program that returns no value is a…Pascal හි අගයක් ආපසු නොදෙන උප වැඩසටහනක්…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Procedure.Procedure.
4“Write once, use many times” describes…“එක් වරක් ලියන්න, බොහෝ වර භාවිත කරන්න” විස්තර කරන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Reusability.නැවත භාවිතය.
5Fixing a job in one place only shows…කාර්යයක් එක් තැනක පමණක් නිවැරදි කිරීම පෙන්වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Maintainability.නඩත්තුව.
6Clear names such as PrintLine improve…PrintLine වැනි පැහැදිලි නම් වැඩි දියුණු කරන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Readability.කියවීමේ පහසුව.
7GetGrade(82) returns…GetGrade(82) ආපසු දෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
82 ≥ 75.82 ≥ 75.
8GetGrade(47) returns…GetGrade(47) ආපසු දෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
35 ≤ 47 < 50.35 ≤ 47 < 50.
9area(5, 4) + area(6, 3) equals…area(5, 4) + area(6, 3) සමාන වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
20 + 18.20 + 18.
10In def area(length, width):, length and width are…def area(length, width): හි length සහ width…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Parameters.පරාමිති.
11The Python keyword that defines a sub-program is…උප වැඩසටහනක් නිර්වචනය කරන Python මූල පදය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
def.def.
12In Python, a function gives back its result with…Python හි ශ්රිතයක් ප්රතිඵලය ආපසු දෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
return.return.
13In Pascal, a function returns a value by…Pascal හි ශ්රිතයක් අගයක් ආපසු දෙන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
GetGrade := ‘A’.GetGrade := ‘A’.
14ShowItem(‘Eggs’, 55, 6) displays…ShowItem(‘Eggs’, 55, 6) පෙන්වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
55 × 6.55 × 6.
15Which is a built-in Python function?ගොඩනැගූ Python ශ්රිතයක් කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Built-in.ගොඩනැගූ.
MCQ answer keyMCQ පිළිතුරු
- D – Sub-program.උප වැඩසටහන.
- A – Function.ශ්රිතය.
- C – Procedure.Procedure.
- C – Reusability.නැවත භාවිතය.
- A – Maintainability.නඩත්තුව.
- A – Readability.කියවීමේ පහසුව.
- D – 82 ≥ 75.82 ≥ 75.
- B – 35 ≤ 47 < 50.35 ≤ 47 < 50.
- D – 20 + 18.20 + 18.
- B – Parameters.පරාමිති.
- C – def.def.
- B – return.return.
- A – GetGrade := ‘A’.GetGrade := ‘A’.
- B – 55 × 6.55 × 6.
- C – Built-in.ගොඩනැගූ.
Structured Questionsව්යුහගත ප්රශ්න
1State three advantages of using sub-programs. (3 marks)උප වැඩසටහන් භාවිතයේ වාසි තුනක් සඳහන් කරන්න. (ලකුණු 3) (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2Distinguish between a value-returning and a non-value-returning sub-program with an example of each. (4 marks)අගයක් ආපසු දෙන සහ ආපසු නොදෙන උප වැඩසටහන් එක් එකකට උදාහරණයක් සමඟ වෙන්කර දක්වන්න. (ලකුණු 4) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Write a function (Pascal or Python) that receives a mark and returns the O/L grade A, B, C, S or W. (5 marks)ලකුණක් ලබාගෙන O/L ශ්රේණිය A, B, C, S හෝ W ආපසු දෙන ශ්රිතයක් (Pascal හෝ Python) ලියන්න. (ලකුණු 5) (5 marksලකුණු 5)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
program GradeFunction; var k, m: integer; function GetGrade(marks: integer): char; begin if marks >= 75 then GetGrade := 'A' else if marks >= 65 then GetGrade := 'B' else if marks >= 50 then GetGrade := 'C' else if marks >= 35 then GetGrade := 'S' else GetGrade := 'W'; end; begin for k := 1 to 3 do begin write('Enter mark: '); readln(m); writeln('Grade: ', GetGrade(m)); end; end.
def get_grade(marks): if marks >= 75: return "A" elif marks >= 65: return "B" elif marks >= 50: return "C" elif marks >= 35: return "S" else: return "W" for k in range(3): m = int(input("Enter mark: ")) print("Grade:", get_grade(m))
▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter mark: 82 Grade: A Enter mark: 47 Grade: S Enter mark: 66 Grade: B
4def area(length, width): return length * width
What is displayed by print(area(5, 4) + area(6, 3))? Name the parameters and arguments. (3 marks)def area(length, width): return length * width
print(area(5, 4) + area(6, 3)) මගින් පෙන්වන්නේ කුමක්ද? පරාමිති සහ තර්ක නම් කරන්න. (ලකුණු 3) (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Write a procedure ShowItem that receives an item name, price and quantity and displays the item total. Show one call. (4 marks)අයිතම නමක්, මිලක් සහ ප්රමාණයක් ලබාගෙන අයිතම මුළු මුදල පෙන්වන ShowItem ක්රියා පටිපාටියක් ලියන්න. එක් කැඳවීමක් පෙන්වන්න. (ලකුණු 4) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
program BillProcedures; procedure PrintLine; begin writeln('------------------------'); end; procedure ShowItem(item: string; price, qty: integer); begin writeln(item, ': Rs. ', price * qty); end; begin PrintLine; writeln('SAMPLE SHOP BILL'); PrintLine; ShowItem('Bread', 120, 2); ShowItem('Milk packet', 280, 1); ShowItem('Eggs', 55, 6); PrintLine; end.
def print_line(): print("-" * 24) def show_item(item, price, qty): print(item + ": Rs.", price * qty) print_line() print("SAMPLE SHOP BILL") print_line() show_item("Bread", 120, 2) show_item("Milk packet", 280, 1) show_item("Eggs", 55, 6) print_line()
▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්රතිදානය
------------------------ SAMPLE SHOP BILL ------------------------ Bread: Rs. 240 Milk packet: Rs. 280 Eggs: Rs. 330 ------------------------
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- Sub-program = named part doing one job.උප වැඩසටහන = එක් කාර්යයක් කරන නමක් ඇති කොටස.
- Benefits: reusability, readability, maintainability.වාසි: නැවත භාවිතය, කියවීමේ පහසුව, නඩත්තුව.
- Function returns a value.ශ්රිතය අගයක් ආපසු දෙයි.
- Procedure returns no value.ක්රියා පටිපාටිය අගයක් ආපසු නොදෙයි.
- Parameters receive; arguments are sent.පරාමිති ලබා ගනී; තර්ක යවයි.
- Python: def … return.Python: def … return.
- Pascal: FunctionName := value.Pascal: FunctionName := value.
- Built-ins: print, len, writeln, sqrt.ගොඩනැගූ: print, len, writeln, sqrt.
