උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
4
2. ආදොනය පහෝ ප්රතිදොනය - Input / Output
උදොහරණ:
3. සැකසීම -Process
උදොහරණ:
4. දත් ගැලීම - Data Flows / Flow line
5. තීරණ - Decision
Yes No
උදොහරණ:
Yes No
6. සම්බන්නධකය - Connector
7. අනු සැකසුම - Sub Process
jHdc fla;/ කල්ි පක් (Pseudocode)
mß.Kl jevigykla ilia lsÍfï§ l%uf,aLhla jvd;a myiqfjka we,af.dß;uhla f;areï .ekSu i`oyd jHdc
fla; Ndú;d lrhs' fuys§ bx.%Sis NdIdfõ jpk Ndú;dlr Wmfoia ud,dj ilia flf¾' fuu jpk lsisÿ l%uf,aL
NdIdjlg Ndú;dlrk jpk fkdjQj;a tAjd fndfyda ÿrg tA yd iudk njla fmkakqï lrhs'
ආදොනය
Get, read, input
Eg:- Get mark
Read mark
Input Marks Display total
Total = a+b
a
>
b
11.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
5
ප්රතිදොනය
Output, Display, Print
Eg:- Display total
Print total
සැකසීම
Set, process, calculate
Eg:- Set total = 0
yia; f¾LKh (Hand trace)
yia; l%u Ndú;fhka fla;kh lrk ,o l%uf,aLkh wod, o;a; wdodkh lsÍfuka wod, o;a; Ndú;d lr th
ksjerÈj l%shd;aul lrk wdldrh ne,Sug ks¾udkh lrk ,o j.=j yia; f¾Lkh f,i y`ÿkajhs'
Step
Input Process Output
A B C Total= A+B+C Result
1 10 20 30 10+20+30=60 60
2 70 60 70 70+60+70=200 200
3 60 40 30 60+40+30=130 130
4 10 10 20 10+10+20=40 40
ගැලීම් සටහන්න සහ වයොජ පක් සඳහො උදොහරණ
1. සංඛයො පදකක් ආදොනය කර එම සංඛයො පදපකහි එකතුව පසවීම සඳහො ගැලීම් සටහනක් ඇඳ එයට අදොල
වයොජපක් යක් සහ ෙයි න්න ක්රමපල්ඛනයක් ලියන්නන.
ගැලීම් සටහන වයොජපක් ය ෙයි න්න ක්රමපල්ඛනය
2. සෘජුපකෝණොස්රයක වර් ගඵලය පසවීම සඳහො ගැලීම් සටහනක් ඇඳ එයට අදොල වයොජපක් යක් සහ ෙයි න්න
ක්රමපල්ඛනයක් ලියන්නන.
Begin
Input N1,N2
Process Total=N1+N2
Print Total
End
n1=int(input('Enter number 1:'))
n2=int(input('Enter number 2:'))
total =n1+n2
print('Total is',total)
12.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
6
ගැලීම් සටහන වයොජපක් ය ෙයි න්න ක්රමපල්ඛනය
Begin
Input Length, Breadth
Process Area=Length*Breadth
Print Total
End
l=int(input(Enter Length:'))
b=int(input('Enter Breadth:'))
area =l*b
print('Area is’, area)
13.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
7
3' ixLHd ;=kla wdodkh lr tajdfha tl;=j iy idudkH fiùug wdod, .e,Sï igykla weo thg wod,
jHdcfla;hla iy mhs;ka l%uf,aLkhla ,shkak'
4' ixLHd folla wdodkh lr úYd,;u ixLHdj fiùug wdod, .e,Sï igykla weo thg wod, jHdcfla;hla
iy mhs;ka l%uf,aLkhla ,shkak'
5' 1 isg 5 olajd ixLHdj uqද්රනය කිරීමට wdod, .e,Sï igykla weo thg wod, jHdcfla;hla iy mhs;ka
l%uf,aLkhla ,shkak'
X<=5
Pseudocode
Begin
Input no1, no2, no3
Total=no1+no2+no3
Average=Total/3
Print Total, Average
End
Python Code
n1=int(input('Enter a number 1: '))
n2=int(input('Enter a number 2: '))
n3=int(input('Enter a number 3: '))
total=n1+n2+n3
average=total/3
print('Total is : ',total)
print('Average is : ',average)
Pseudocode
Begin
Input no1, no2, no3
If no1>no2 then
Max=na1
Else
Max=no2
End if
Print max
End
Python Code
n1=int(input('Enter a number 1: '))
n2=int(input('Enter a number 2: '))
if n1>n2:
max=n1
else:
max=n2
print('maximum number is :',max)
Pseudocode
Begin
x=1
while x<=5 do
print x
x=x+1
end while
End
Python Code
x=1
while x<=5:
print(x)
x=x+1
Start
X=1
Print x
Stop
yes
no
Start
n1>n2
Input n1, n2
Stop
yes
no
Max
n1
Max
n2
Start
Input n1, n2, n3
Total = n1+n2+n3
Average=total/3
Print Total, Average
Stop
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
33
1' set (mutable)
2. Frozenset (immutable)
>>> x=[5,6,7,5,9,8]
>>> y=set(x)
>>> print(y)
{5, 6, 7, 8, 9}
X keue;s list tflys 5 b,lalï folla we;' kuq;a th set tlla njg m;a l, miq wkqmsgm;a bj;aù we;s nj
fmfka' ;jo Set {} jryk u.ska ksrEmkh fõ'
>>> fruits=['mango','banana','apple','mango']
>>> x=set(fruits)
>>> x
{'apple', 'banana', 'mango'}
>>> animals={'cat','dog','bat','rat','fish','cat'}
>>> print(animals)
{'fish', 'cat', 'bat', 'rat', 'dog'}
>>> 'cat' in animals
True
>>> 'lion' in animals
False
>>> 'lion' not in animals
True
>>> 'lion' is animals
False
>>> 'lion' is not animals
True
idudkH .Ks;fhaoS Ndú;d lrkq ,nk l=,l (set) j, Ndú;d lrk .Ks;l¾u fuysoSo isÿlr.; yel'
1' Union
2. Intersection
3. Difference
4. Symmetric difference
>>> x=('aruna')
>>> y=('waruna')
>>> x=set('aruna')
>>> y=set('waruna')
>>> x
{'a', 'r', 'n', 'u'}
>>> y
{'r', 'w', 'a', 'n', 'u'}
>>> y-x # letters in y but not in x
{'w'}
>>> x|y #letters in either x or y
40.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
34
{'a', 'r', 'w', 'n', 'u'}
>>> x&y # letters in both x and y
{'a', 'r', 'n', 'u'}
>>> x^y # letters in x or y but not both
{'w'}
mhs;ka NdIdfõ Ndú;d jk .Ks; l¾u (Python Basic Operators)
1. wxl .Ks;uh ldrl (Arithmetic Operators)
2. ixikaokd;aul ldrl (Comparison Operators)
3. ;d¾lsl ldrl (Logical Operators)
4. wdfoaYk ldrl (Assignment Operators)
5. ìgq wkqidß; ldrl (Bitwise Operators)
wxl .Ks;uh ldrl (Arithmetic Operators)
a = 21
b = 10
c = 0
c = a + b
print ("Value of c is ", c)
c = a - b
print ("Value of c is ", c )
c = a * b
print ("Value of c is ", c )
c = a / b
print ("Value of c is ", c )
c = a % b
print ("Value of c is ", c)
a = 2
b = 3
c = a**b
print ("Value of c is ", c)
a = 10
b = 5
c = a//b
print ("Value of c is ", c)
ldrlh úia;rh ksoiqk (x=5, y=2 kï)
+ tl;= lsÍu x+y=7
- wvq lsÍu x-y=3
* .=K lsÍu x*y=10
/ fnoSu x/y=2.5
% fY%aIh (mod) x%y=1
** n,h x**y=25
// mQ¾K ixLHdjlg fnoSu (Floor Division) x//y=2
41.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
35
ixikaokd;aul ldrl (Comparison Operators)
w.hka folla fyda lsysmhla ixikaOkh lr m%;sodkh True fyda False f,i ,ndfohs'
a = 21
b = 10
c = 0
if (a == b):
print ("a is equal to b")
else:
print ("a is not equal to b")
if (a! = b):
print ("a is not equal to b")
else:
print ("a is equal to b")
if (a < b):
print ("a is less than b”)
else:
print ("a is not less than b")
if (a > b):
print ("a is greater than b")
else:
print ("a is not greater than b")
a = 5;
b = 20;
if (a <= b):
print ("a is either less than or equal to b")
else:
print ("a is neither less than nor equal to b")
if (b >= a):
print ("b is either greater than or equal to b")
else:
print ("b is neither greater than nor equal to b")
;d¾lsl ldrl (Logical Operators)
and, or iy not hk ;d¾lsl fufyhjk Ndú;d jk ldrl fuhg wh;afõ'
ldrlh úia;rh ksoiqk (x=5, y=2 kï)
== iudkhs x=y →False
!= wiudkhs x!=y →True
> úYd,hs x>y →True
< l=vhs x<y → False
>= úYd,hs fyda iudkhs x>=y → True
<= n,h x <=y →False
42.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
36
a = 10
b = 20
c = 0
if (a and b):
print ("a and b are true")
else:
print ("Either a is not true or b is not true")
if (a or b):
print ("Either a is true or b is true or both are true")
else:
print ("Neither a is true nor b is true")
a = 0
if (a and b):
print ("a and b are true")
else:
print ("Either a is not true or b is not true")
if (a or b):
print ("Either a is true or b is true or both are true")
else:
print ("Neither a is true nor b is true")
if not(a and b):
print ("Either a is not true or b is not true")
else:
print ("a and b are true")
wdfoaYk ldrl (Assignment Operators)
lsishï úp,Hhla i`oyd w.hla wdfoaY lsÍfïoS fhdod.; yels fufyhjkhls' fuysoS wdfoaYjk úp,Hh
operand f,i y`ÿkajhs'
ldrlh úia;rh ksoiqk (x=5, y=2 kï)
and ;d¾lsl and x=y and x>y →false
x!=y and x>y →true
or ;d¾lsl or x!=y or x<y →true
x>y or x!=y →true
not ;d¾lsl not not(x>y) →false
not(x!=y) →true
ldrlh úia;rh ksoiqk (x=5, y=2 kï)
= ol=Kq mi w.h jïmi w.hg wdfoaY lsÍu y=x →y=5
+= ol=Kq mi we;s w.h jïmi w.hg tl;=lr
m%;sM,h k%eje; jïmig wdfoaY lsÍu
x+=y →x=7
-= Jïmi w.fhka ol=Kqmi w.h wvqlr m%;sM,h
keje; jïmig wdfoaY lsÍu
x-=y →x=3
*= ol=Kq mi w.h jïmi w.fhka .=Klr m%;sM,h
jïmig wdfoaY lsÍu
x*=y → x=10
43.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
37
a = 8
b = 3
c = 0
c = a + b
print ("Value of c is ", c)
c += a
print ("Value of c is ", c )
c *= a
print ("Value of c is ", c )
c /= a
print ("Value of c is ", c )
c = 2
c %= a
print ("Value of c is ", c)
c **= a
print ("Value of c is ", c)
c //= a
print ("Value of c is ", c)
ìgq wkqidß; ldrl (Bitwise Operators)
oajsuh ixLHdu; mokï .Kkh lsÍï i`oyd Ndú;d lrhs' hï w.hka folla úp,Hhka Ndú;fhka we;=,;a
l, miq tu ixLHdjka j,g wod< oaúuh w.hka ,ndf.k .Kkh lsÍï isÿlr m%;sM,h oYuh wdldrfhka
,nd.; yel'
Binary AND
x=15 හො y=11 f,i.uq'
Binary OR
x=15 හො y=11 f,i.uq'
/= jïmi w.h ol=Kq mi w.fhka fnod m%;sM,h
jïmig wdfoaY lsÍu
x/=y →x=2.5
%= jïmi w.h ol=Kq mi w.fhka fnod fYaIh
jïmig wdfoaY lsÍu
x%=y →x=1
**= jïmi w.fha n,h ol=Kqmi w.h f,i f.k
ms<s;=r keje; jïmig wdfoaY lsÍu'
x**y →x=25
//= jïmi w.h ol=Kq mi w.fhka fnod ms<s;=r
mQ¾K ixLHdjla f,i jïmig wdfoaY lsÍu
x//y →x=2
ldrlh úia;rh ksoiqk (x=15, y=11 kï)
& Binary AND x&y → 11
| Binary OR x|y → 15
^ Binary XOR x^y → 4
~ Ones Complement (m<uq wkqmQrlh) ~x →-16, ~y →-12
<< Left shift (jug iSreudre lsÍu) x>>2 → 3, y>>2 →2
>> Right shift (ol=Kg iSreudre lsÍu) x<<2 → 60, y>>2 →44
x 0 0 0 0 1 1 1 1
y 0 0 0 0 1 0 1 1
x&y 0 0 0 0 1 0 1 1
oYuh w.h 11
x 0 0 0 0 1 1 1 1
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
39
a = 60 # 60 = 0011 1100
b = 13 # 13 = 0000 1101
c = 0
c = a & b; # 12 = 0000 1100
print ("Value of c is ", c)
c = a | b; # 61 = 0011 1101
print ("Value of c is ", c)
c = a ^ b; # 49 = 0011 0001
print ("Value of c is ", c)
c = ~a; # -61 = 1100 0011
print ("Value of c is ", c)
c = a << 2; # 240 = 1111 0000
print ("Value of c is ", c)
c = a >> 2; # 15 = 0000 1111
print ("Value of c is ", c)
Membership Operators
fuysoS in iy not in කොරක භොවි ො කරයි. යම්කිසි විචලයයක් තුල අන්න ර්ග දත් යක් නම් ස යය පලසත්
අන්න ර්ග පනොවන දත් යක් නම් අස යය පලසත් දැක්වීම සිදුපේ. ස යය බව දැක්වීමට in කොරකයද අස යය බව
දැක්වීමට not in කොරකයද භොවි ො කරයි.
>>> a=[1,2,3,5]
>>> print (3 in a)
True
>>> print(4 in a)
False
Identity Operators
fuysoS is iy is not කොරක භොවි ො කරයි. යම්කිසි විචලයය පදකක් සසඳො එක් විචලයයක් තුල අන්න ර්ග දත් යක්
අපනත් විචලයය තුල ෙවතීනම් ස යය (True) පලසත් අන්න ර්ග පනොවන දත් යක් නම් අස යය (False) පලසත්
දැක්වීම සිදුපේ. ස යය බව දැක්වීමට is කොරකයද අස යය බව දැක්වීමට is not කොරකයද භොවි ො කරයි.
>>> a=5
>>> b=5
>>> if a is b:
print('a equal to b')
else:
print('a not equalt to b')
Output
a equal to b
>>> a=5
>>> b=5
46.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
40
>>> if a is not b:
print(' a not equal to b’)
else:
print(''a equal to b ')
Output
a equal to b
කාරක ප්රමුඛතාවය
ෙයි න්න ක්රමපල්ඛන භොෂොපේදී ෙහ සඳහන්න කොරක ප්රමුඛ ො අනුිළිපවල භොවි ො කරයි.
>>> 5+2*3
11
>>> 5-2*6
-7
>>> 6+2**3
14
>>> (5+2)//2+2**4
19
>>> 5/2+3
5.5
>>> 4/2+5//2
4.0
ප්රමුඛතා මට්ටම කාරකය ප්රමුඛ ොවය වැඩි
ප්රමුඛ ොවය අඩු
1 **
2 - + ~ (unary plus and minus), complement
3 * / % //
4 + -
5 >> <<
6 &
7 ^ |
8 <= < > >=
9 == !=
10 = += -= *= /= %= //= |= &= >>= <<= **=
11 is, is not
12 in, not in
13 not, and, or
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
43
x=1
while x<=5:
print(x)
x=x+1
For loop
j.ka;shla fyda lsysmhla ksIaÑ; jdr .Kkla mqk¾lrKh lsÍug Ndú;d fõ' fuh fhdod.; yelafla wjia:d
folloS muks'
1' hïlsis ixLHd mrdihla ;=, mqk¾lrKh i`oyd
2' o;a; ,ehsia;=jla Ndú;d lsÍu i`oyd
>>> for x in range(5):
print(x)
0
1
2
3
4
>>> for x in range(1,5):
print(x)
1
2
3
4
>>> for x in range(1,5,2):
print(x)
1
3
>>> city='polonnaruwa'
>>> for i in city:
print(i)
p
o
l
o
n
n
a
r
u
w
a
>>> x=['a','aruna','ict',5,2]
>>> for i in x:
50.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
44
print(i)
a
aruna
ict
5
2
Nested loop
mqk¾Khla ;=, ;j;a mqk¾lrKhla fhfok úg Ndú;d lrhs'
WodyrK ( 1 isg 20 olajd we;s m%:ul ixLHd ,nd.ekSu
i = 2
while(i < 20):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) :
print (i, " is prime")
i = i + 1
WodyrK ( 2 iy 3 .=Kk j.= ,nd.ekSu'
for i in range (2,4):
print (i, 'multiplication table')
print ('------------------------')
for x in range(1,13):
print(i,'*',x,'=',i*x)
51.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
45
mqk¾lrKhla ;=, jrKhla fhoSu
WodyrK ( 1 isg 15 olajd we;s T;af;a iy brÜfÜ ixLHd fjk fjku m%;sodkh lsÍu'
for i in range(16):
if i%2==0:
print(i,'is an even number')
else:
print(i,'is an odd number')
52.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
46
mqk¾lrK md,k j.ka;s (Loop control statements)
Break Statement
mqk¾lrKhla ls%hd;aul fjñka mj;sk wjia:djl w;ru.ska mqk¾lrKh k;r lr .ekSu i`oyd fhdod.;
yel'
WodyrK ( 1 isg 5 olajd ixLHd uqøKh jk l%uf,aLhl 3jk ixLHdfõoS l%uf,aLh k;r lsÍu'
x=1
while x<=5:
if x==3:
break
print(x)
x=x+1
WodyrK ( polonnaruwa hk jpkfha n wl=f¾oS l%uf,aLkh k;r lsÍu'
for i in 'polonnaruwa':
if i=='n':
break
print(i)
Continue Statement
mqk¾lrKhl iuyr m%ldYk w;yer B,. m%ldYkhg hdu isÿfõ'
WodyrK ( 1 isg 5 olajd ixLHd uqøKh jk l%uf,aLhl 3jk ixLHdj w;yer l%uf,aLh ls%hd;aul lsÍu'
for i in range(1,6):
if i==3:
continue
print(i)
WodyrK ( polonnaruwa hk jpkfha n wl=re w;yer B<. wl=re uqøkh lsÍu'
for i in 'polonnaruwa':
if i=='n':
continue
print(i)
Pass Statement
mqk¾lrKhla ls%hd;aulùfïoS w;rueo hïlsis jdlHhla tla l< hq;= kï fuh Ndú;d lrhs'
WodyrK ( 1 isg 5 olajd ixLHd uqøKh jk l%uf,aLhl 3jk ixLHdjg fmr ict institute f,i tlalr
l%uf,aLh ls%hd;aul lsÍu'
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
48
return statement
Ys%;hla le`ojk iEu wjia:djlu w.hla uqodyÍ' th return hk mhs;ka uQ,moh u`.ska m%Odk l%uf,aLhg
w.hla uqodyeÍu isÿl, yelsh' uqodyßk ,o j.ka;sfha Ys%;h ;=, w.hla fkdue;s úg None hk w.h ,ndfoa'
.eg¨j 1
ixLHd folla wdodkh lr tajdfha tl;=j ,nd.ekSug l%uf,aLkhla Ys%; Ndú;fhka ,sùu'
#function
def sum(x,y):
print('Total is :',x+y)
#program
x=int(input('Enter a number 1: '))
y=int(input('Enter a number 2: '))
sum(x,y)
.eg¨j 2
m<uq ku" fojk ku iy wjidk ku we;=,;a lr uq,l=re iu`. wjidk ku oelaùu i`oyd mhs;ka
l%uf,aLkhla ,shkak'
#function
def name(fn,sn,ln):
print(fn[0],'.',sn[0],'.',ln)
#program
fn=input('Enter first name: ')
sn=input('Enter second name: ')
ln=input('Enter last name: ')
name(fn,sn,ln)
.eg¨j 3
m<uq ku" fojk ku" wjidk ku" jdi.u" ia;S%$ mqreI nj iy újdyl wújdyl nj we;=,;a lr Mr, Mrs.
fyda Miss. we;=,;a uq,l=re iu`. jdi.u oelaùu i`oyd mhs;ka l%uf,aLkhla ,shkak'
#function
def name(fn,sn,ln,su,g,c):
if g=='male':
s='Mr'
elif g=='female':
if c=='maried':
s='Mrs'
else:
s='Miss'
#function
def sum(x,y):
return x+y
#program
x=int(input('Enter a number 1: '))
y=int(input('Enter a number 2: '))
print('Total is :',sum(x,y))
55.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
49
print(s,'.',fn[0],'.',sn[0],'.',ln[0],'.',su)
#program
fn=input('Enter first name: ')
sn=input('Enter second name: ')
ln=input('Enter last name: ')
su=input('Enter surname: ')
g=input("Enter 'male' or 'female' :")
c=input("Enter 'married' or 'unmarried' :")
name(fn,sn,ln,su,g,c)
උදොහරණ 1
def changeme( mylist ):
"This changes a passed list into this function"
mylist = [1,2,3,4]; # This would assign new reference in mylist
print ("Values inside the function: ", mylist)
return
# Now you can call changeme function
mylist = [10,20,30];
changeme( mylist );
print ("Values outside the function: ", mylist)
Output
Values inside the function: [1, 2, 3, 4]
Values outside the function: [10, 20, 30]
උදොහරණ 2
# Function definition is here
def printinfo( name, age ):
"This prints a passed info into this function"
print ("Name: ", name)
print ("Age :", age)
return;
# Now you can call printinfo function
printinfo( age=38, name="aruna" );
Output
Name: aruna
Age : 38
උදාහරණ 3
# Function definition is here
def printinfo( name, age = 17 ):
"This prints a passed info into this function"
print ("Name: ", name)
print ("Age :", age)
56.
උසස් පෙළ පොරතුරු හො සන්නිපේදන ොක්ෂණය- ICT ගුරුවරුන්න ෙමණයි සමූහය
50
return;
# Now you can call printinfo function
printinfo( age=18, name="kasun" );
printinfo( name="supun" );
Output
Name: kasun
Age : 18
Name: supun
Age : 17
උදොහරණ 4
# Function definition is here
sum = lambda arg1, arg2: arg1 + arg2;
# Now you can call sum as a function
print ("Value of total : ", sum( 10, 20 ))
print ("Value of total : ", sum( 20, 20 ))
Output
Value of total : 30
Value of total : 40
ශ්රි විස් ොරයන්න (function arguments)
ෙයි න්න ෙරිගණක භොෂොපේදී ශ්රි විස් ොරයන්න කිහිෙයක් භොවි ො කරයි. ඒවො ෙයි න්න ශ්රි වල ඇති විපශ්ෂොංග පලසඳ
හැඳින්නවිය හැක.
1. Default arguments
2. Keyword arguments
3. Required arguments
4. Variable arguments
Default arguments
ශ්රි ිරවචනපේදී ස්වයං ෙැවැරූ අගයන්න භොවි ො කළ හැකිය. යම් අගයක් ශ්රි ය කැදවීපම්දී පනොමැති නම් ශ්රි ය තුල
අන්න රග ස්වයං ෙැවැරූ අගය කැඳවීම සිදුකරයි.
#default arguments
#function
def myself(name='kamal',age=38,address='kaduruwela'):
print('Name is : ',name)
print('Age is :',age)
print('Address is :',address)
return
#program
myself(name='aruna',address='polonnaruwa')
Output
Name is : aruna
Age is : 38
Address is : polonnaruwa
Name is : herath
Age is : 35
Address is : kaduruwela
77
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
<HR SIZE = 10 WIDTH = 40 NOSHADE>
wkq,laIK fudaia;r
• <B>—</B> - The <B> tag displays the enclosed text in the bold type.
• <BIG>—</BIG> -The <BIG> tag increased the size of the enclosed text. The exact
appearance of
the text depends on the browser and the default font size.
• <EM>—</EM> - The <EM> is used to emphasize text. The enclosed text is usually
displays in
italics
• <I>—</I> - The <I> tag italicizes the enclosed text.
• <SMALL>—</SMALL> - The <SMALL> tag decreases the size of the enclosed text.
The exact
appearance of the text depends on the browser and the
default font size.
• <SUB>—</SUB> - The <SUB> tag displays the enclosed text as a subscript.
• <SUP>—</SUP> - The <SUP> tag displays the enclosed text as a superscript.
• <TT>—</TT> - The <TT> tag displays text in a fixed width, teletype style font.
• <U>—</U> - The <U> tag underlines the enclose text. The <U> tag should be
avoided because it
will confide users with hypertext, which is typically underlined.
Example
<HTML><HEAD><TITLE>Test Page</TITLE></HEAD>
<BODY>
<H1>Character Emphasis </H1>
<P>this is <EM>Emphasis (Usually Italic)
</EM> text
<P>this is <STRONG>Stronger emphasis
(Usually bold)</STRONG> text
<P>this is <TT>Teletext </TT> text
<P>this is <B>Bold</B> text
<P>this is <I>Italic</I> text
<P>this is <U>Underline</U> text
<P>this is <BIG>BIGGER</BIG> text
<P>this is <SMALL>SMALLER</SMALL> text
<P>this is <SUB>Subscripted</SUB> text
<P>this is <STRIKE>Strike through</STRIKE> text
<P>this is <SUP>Superscripted</SUP> text
</BODY></HTML>
'HTML' Ndú;fhka ilia lrk fjí msgq i|yd Ndú; lrkq ,nk wkq,laIK úúO
wdldrfhka fjkia lrñka fjí msgqj, ndysr fmkqu w,xldr l< yels h' fï i|yd wkq,laIK
WmfoaY fla; (Character Tag) Ndú; l< yels h' fuu WmfoaY fla; wjYH jk wlaIrhg fyda
84.
78
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
jpkhg fyda jdlH ldKavhlg fyda jdlHhlg fyda fþohlg fyda fhdÞ .; yels h' fuu
wkq,laIK WmfoaY fla; Ndú; lsÍfï § tys wjidkh fld;k±hs oelaúh wksjd¾h h'
iuyr f,aLk fudaia;r (Document Styles) Ndú; lrkq ,nk wdldrh wkqj fjkia
jk w;r iuyr wjia:dj, § fuu fla; ;¾ldkql+, (Logical) wdldrhlg l%shd lrkq ,efí'
wl=re j¾.fhys m%udKh iy j¾Kh
<FONT>—</FONT> - The <FONT> tag used to control the appearance of the text it
encloses.
SIZE - Value Size of the font in points, it can be absolute or relative. Specifying
SIZE = 5 - sets the font size to 5 points. Specifying
SIZE - +5 set the font size 5 points larger than default tag.
COLOR - Colour The colour of the enclosed text.
FACE - List The font faces of the text. Multiple font face can be specified,
separated by
commas. The browser will try to render the text in the order specified by
the list.
'HTML' ys <FONT> WmfoaY fla;h iu. tys wkq WmfoaY fla; Ndú; lr.ksñka
wlaIrhka ys m%udKh (Size) iy j¾Kh (Color) fjkia l< yels h' fuu wu;r wkq WmfoaY
fla; Ndú; lr.ksñka j¾Kj;a wlaIr iys; fjí msgq ilia lsÍug myiqlï ie,iS we;'
wl=re j¾.fhys m%udKh
<FONT SIZE = n >
fï i|yd wdldr folla Ndú; l< yels h' m<uq l%uh wlaIrfha m%udKh ksYaÑ; jYfhka
i|yka lsÍu fõ' fuys 'n' m%udKfha w.h 1 isg 7 olajd fjkia fõ'
n ys w.h 1 iy 2 l=vd m%udK i|yd;a (Small Size)
n ys w.h 3 idudkH m%udKh i|yd;a (Normal Size)
n ys w.h 4 isg 7 olajd úYd, m%udK i|yd;a (Large Size) fhdÞ .efka'
Example
<HTML><HEAD><TITLE>Test Page</TITLE></HEAD>
<BODY>
<H1>Font size and colour</H1>
<FONT SIZE=4 COLOR=”#0000FF”>
<P>This font is in Blue</FONT>
<FONT SIZE=6>
<P>This font is in size 6</FONT>
<FONT SIZE=3 COLOR=”black”>
<P>This font is in size 3 and Black
color</FONT>
</BODY></HTML>
85.
79
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
wkq,laIK j¾Kh
wlaIrj, j¾Kh <FONT> WmfoaY fla; iuÕ 'COLOR' wkq WmfoaY fla;h Ndú;
lrñka fjkia l< yels h'
<FONT COLOR ="#RRGGBB">
wlaIrhka ys j¾Kh fjkia lsÍu i|yd Iâ oYu (Hexadecimal) ixLHd 3la Ndú; l<
hq;= h' r;=" fld< iy ks,a j¾Kh i|yd fjk fjku Iâ oYu ixLHd Ndú; l< hq;= jk w;r
tu iEu j¾Khlu w.h oYu ixLHd 0 isg 255 olajd fjkia l< yelsjk w;r tu oYu ixLHd
'HTML' ,sms ilia lsÍfï § Iâ oYuixLHd j,ska ±laúh hq;= h'
by; i|yka lrk ,o oYu ixLHd 0 isg 255 olajd jQ w.hhka Iâ oYu ixLHd l%uhg
wkqj z00Z isg 'FF' olajd fjkia jk w;r" by; i|yka lrk ,o ksoiqkg wkqj 'RR' ^r;=
j¾Kh i|yd&" 'GG' ^fld< j¾Kh i|yd& iy 'BB' ^ks,a j¾Kh i|yd& i|yd fjka fjka Iâ
oYu ixLHd w.hhka wdfoaY l< hq;= h'
WÞyrKhla f,i Iâ oYu w.hla jk '0000FF' ^0"0 iy 255 oYu ixLHd w.hhka
wkqms<sfj<g& ks,a j¾Kh i|yd Ndú; lrkq ,nk w;r tys z00Z w.h r;= j¾Kh i|yd o
fojk Iâ oYu ixLHdj jk z00Z w.h fld< j¾Kh i|yd o ;=kajk Iâ oYu ixLHdj jk
'FF' w.h ks,a j¾Kh i|yd o fhdÞ .efka'
fuys § r;= j¾Kh iy fld< j¾Kh i|yd z00Z fhdÞ f.k ;sîfuka tu j¾K fol
fhdÞ f.k ke;s nj ±lafjk w;r ks,a j¾Kh muKla fhdÞ .efka' ks,a j¾Kh wfkl=;a
j¾K iu. ixl,kh ù fkdue;s nj ie,lsh hq;= h'
tfia u fuu Iâ oYu ixLHdj fjkqjg j¾Khg ysñ kduh o Ndú; l< yel
WÞyrKhla f,i"
<FONT COLOR ="#8F8FBD"> (Light Steel Blue j¾Kh i|yd)
<FONT COLOR ="blue"> ^ks,a j¾Kh i|yd&
igyka #
<FONT> WmfoaY fla;h hgf;a wlaIrhka ys j¾Kh iy tys m%udKh fjkia lsÍu
i|yd wÞ< wkq WmfoaY fla; my; ±lafjk wdldrhg Ndú; l< yels h'
<FONT COLOR ="White" SIZE = 5>
Pre formatted text Ndú;h
Example
<html><head><title> pre formatted </title></head><body>
<pre>
Hello
Welcome to the world of programming
with HTML
With the help of this guide
</pre></body></html>
90
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
<html>
<textarea rows="2" cols="20">
The oldest University in Sri Lanka, the University of Colombo is a
sprawling complex located in the heart of the capital city of Colombo.
</textarea>
<html>
HTML <meta> Tag
HTML Meta data පිලිෙද විස්තර කරයි.
වමහි දත්ත මගින්න out put එකක් web browser තුලින්න වපන්නනුම් වනොකරයි.
උදොහරණ
<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Stale Refsnes">
<meta charset="UTF-8">
<meta http-equiv="refresh" content="30">
</head>
Form සඳහො උදොහරණයක්.
<html> <head>
<title>Registration Form</title>
<link href="main.css" rel="stylesheet" />
<script src="main.js"></script>
</head>
<body>
<form action="tt.php" id="regForm" onsubmit="return validate();">
<div id="mainDiv">
<h1 class="heading1">Regitration Form</h1>
<hr color="blue" />
95
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
2- Internal Style Sheet
• Internal Style Sheet වයොදොගනුවේ එක style එකක් වයොදො ගන්නවන්නනම් ය.
• HTML page එකකhead section(<head>) එක යටවත් වමය ලියනු ලැවබ්.
• වම් සඳහො <style> tag එක වයොදො ගනී.
• පහත උදොහරණය සලකන්නන.
<head>
<styletype="text/css">
hr {color:blue;}
p {margin-left:20px;}
body {background-
image:url("images/back40.gif");}
</style>
</head>
3- Inline Styles
• පහත උදොහරණය මගින්න ඔෙට වමය වහොදින්න වටහො ගත හැක.
• එකම ස්ථොනවේ style sheet එක හො අපිට අවශය HTML code එකද ඇත.
<p
style="color:red ;
margin-left:20px">university
</p>
CSS Background Color
වවබ් පිටුවේ background color එක වයොදන ආකොරය වමහි දැක්වේ.
body {
background-color:#b0c4de;
}
style sheet එකක ිතරම පහත ආකොර වලින්න color දක්වනු ලෙයි.
▪ a HEX value - "#ff0000" වලස
▪ a RGB value -"rgb(255,0,0)" වලස
▪ a color name - "red" වලස
102.
96
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
Color code කීපයක්
<html>
<head>
<style type="text/css">
h1{
background-color:#6495ed;}
p{
background-color:#e0ffff;}
div{
background-color:#b0c4de;}
</style>
</head>
<body>
<h1>Sri lanka</h1>
<div>
Pearl of the Indian Ocean.
<p>Sri lanka is a very beautiful
country.</p>
It is a Island.
</div>
</body>
</html>
101
උසස් පෙළ පොරතුරු සන්නිපේදන ොක්ෂණය - ICT ගුරුවරුන්න සඳහො Facebook සමූහපයහි ප්රකොශනයකි.
• වහොදින්න ෙලන්නන.ඉහත උදොහරණවේ යන්නන Colombo in Sri lanka රතු පැහැ ගත්වත්
වකවස්ද?එම id එකට නමක් ලෙො දී නැත.එම ිසො body එවකහි පොට එයට ලැවබ්.
Text Alignment
පහත උදොහරණය ෙලන්නන. එහිදී සිදු කර ඇත්වත් අප ලියන text වවබ් පිටුවේ මැදට ගැනීමට ඒක
වයොදො ගැනීමයි.
<html>
<head>
<style type="text/css">
h1 {text-align:center;}
p.date {text-align:right;}
p.main {text-align:justify;}
</style>
</head>
<body>
<h1>Sri lanka</h1>
<p class="date">October,2011</p>
<p class="main"> Sri Lanka, officially
the Democratic SocialistRepublic of Sri Lanka is a country off
the southern coast of the Indian subcontinent </p>
<p>
<b>Note:</b> As a result of its location in the path of major
sea routes. </p>
</body> </html>