Professional Documents
Culture Documents
Aslam Sajah: Kandy
Aslam Sajah: Kandy
E (A/L)
ICT
j ah
mSa
Als a SEC
Kandy
? No
X>10
Yes
End
2. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?
h
Begin
(1) 1,6
a
X=1
j
(2) 1,6,11 Do While X>10
Sa
X=X+5
(3) 6,11 Display X
(4) xUNghJk; Muk;gpf;fhJ End While
(5) xUNghJk; KbtilahJ End
ls a m
3. gpd;tUk; Nghypf;Fwpapd; tUtpisT ahJ?
A
X=5 (1) 5
P=3 (2) 8
X=P+X (3) 11
While (X>6) (4) xUNghJk; Muk;gpf;fhJ
Display X (5) xUNghJk; KbtilahJ
End while
4. m vd;gJ xU KO vz; khwp vdpd; gpd;tUk; Nghypf;Fwp Kiw gw;wpa rupahd $w;W
(1) 3 jlitfs; nraw;gLk;
(2) 4 jlitfs; nraw;gLk; m=50
(3) 5 jlitfs; nraw;gLk; While m>3
(4) xU jlitNaDK; nraw;gl khl;lhJ m=m-10
(5) xU NghJk; KbtilahJ
End while
5. m vd;gJ xU KO vz; khwp vdpd; gpd;tUk; Nghypf;Fwp Kiw
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 1 of 15
Python - Revision AL-ICT
6. m, n vd;gJ xU KO vz; khwp vdpd; gpd;tUk; Nghypf;Fwp gw;wpa rupahd $w;W
ah
Begin
j
No
X =1
Sa
Y= 3 End
Do (1) 1
m
Z=x * Y (2) 3
ls a
X=X+1 (3) 27
Until x<10 (4) 30
Display Z
A
(5) 33
End
Begin
x=5
y=3 (1) 1
x=x-y (2) 2
x=y-x (3) 3
display x (4) 4
End (5) 5
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 2 of 15
Python - Revision AL-ICT
Begin
11. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?
x=2
(1) 1 While x<11
(2) 9 x=x+7
(3) 11 End while
(4) 16 Display X
(5) 18 End
h
(4) 16
z= a+b
j a
(5) 20 End while
Sa
Display z
End
13. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?
ls a m
Begin
a=7 (1)5
c=3
A
(2)6
Repeat (3)10
c=c+1
(4)16
a=a+c
(5)22
Until c>5
Print a
End
Begin
x = 10
Do while x > 0
x=x-1
14. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ? y = x MOD 2
If y<>1 Then
(1) 1,2,3,4,5,6,7,8,9,10 Print x
(2) 0,2,4,6 End IF
(3) 0,2,4,6,8 End While
(4) 8,6,4,2 End
(5) 8,6,4,2,0
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 3 of 15
Python - Revision AL-ICT
Begin
x=1 (1) 1
sum=0 (2) 10
for x=1 To 10 (3) 45
sum= sum + x (4) 55
End for (5) 66
Display sum
End
h
(3) 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 print x
a
(4) 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
j
Do whie x<=10
(5) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Sa
y = y+x
print y
17. gpd;tUk; Nghypf;Fwpapd; tUtpisT ahJ? x= x+y
m
print x
ls a
Begin
End while
m=1
Do While m < = 5
A
n=m+1 (1) 1 2 3 4 5
print n (2) 3 4 5 6
End while (3) 2 3 4 5 6
End (4) xUNghJk; ,aq;f Muk;gpf;fhJ
(5) xUNghJk; Kbtila khl;lhJ
p=20
18. gpd;tUk; Nghypf;Fwpapd; tUtpisT ahJ? Do until p>=100
(1) 20, 40, 60, 80, 100 p=p+20
(2) 40, 60, 80, 100 Loop
Print p
(3) 20
(4) 100
(5) 120
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 4 of 15
Python - Revision AL-ICT
19. gpd;tUk; Nghypf;Fwpapd; tUtpisT ahJ?
Begin
(1) 1
A=5
(2) 5
B=50
(3) 10
Do while A<= B
(4) 0 A=B/A
(5) xU NghJk; KbtilahJ. End while
Display A
j ah
def fun(a):
Sa
while(a<10):
return(a)
a=a+1
m
return(a)
ls a
fun(5)
A
(1) 5,6,7,8,9 (2) 5,6,7,8,9,9 (3) 9 (4) 5,6,7,8,9,10 (5) 5
if find a ‘return’ in function, the function will return the value and stop
22. gpd;tUk; igj;jhd; nra;epuypd; tutpisT ahJ?
for i in range(1,6):
print(i, end=" ")
print("End of value i " , i, " ")
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 5 of 15
Python - Revision AL-ICT
(1) A kl;Lk; (2) B kl;Lk; (3) C kl;Lk; (4) D kl;Lk; (5) B, D kl;Lk;
0 4 cannot by -1
h
KiwNa gpd;tUtdtw;Ws; vJ?
j a
(1) set, string, tuple (2) set, list tuple (3) set, string, integer
Sa
(4) dictionary, string, integer (5) set, list, tuple
26. fPNo jug;gl;l igjd; $w;wpid epiwNtw;wk; nra;j gpd;G khwp X ,d; ngWkhdk; ahJ ?
ls a m
X =13+5**(2%7)//3*5>>3
A
(1) 13 (2) 53 (3) 6 (4) 8 (5) 3
= 13 + 25 // 3*5 >>3
= 13 + 8*5 >>3
= 13+40 >>3
= 53 >> 3
= 110101 >> 3
= 110 = 6
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 6 of 15
Python - Revision AL-ICT
28. gpd;tUk; igjd; juT tiffisf; fUJf.
A– 5
B– {‘student’:’Bala’, ‘Subject’:’ICT’}
C– 6.0
NkNy jug;gl;l juT tiffs; KiwNa
(1) tuple, dictionary, float (2) integer, dictionary, float (3) integer, list, float
(4) integer, set, float (5) tuple, set, float
for i in range(2,10,2):
if(i=="6"):
continue
print(i ,end=” “)
ah
(1) 2 4 6 (2) 6 (3) 2 4 6 8 (4) 2 4 8 10 (5) 2
Saj
here, “6”is string value so, 6 not skip
continue - skip
m
Explain Break - terminate
ls a
30. jug;gl;l igjd; nra;epuiy nraw;gLj;Jk; NghJ ngwg;gLk; tUtpisT ahJ?
A
(1) [`d`, `c`, `ptiv`, `eness`] (2) [`d`, `c`, `ptiveness`] x= ‘deceptiveness’
(3) [`dece`, `ptiveness`] (4) [`dece`, `ptiv`,`r`, `ess`] x.split(`e`,2)
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 7 of 15
Python - Revision AL-ICT
f1=Open(`input.txt`, `r`)
f2 = Open (`output.txt`, `w`)
For line in f1:
data = (line.strip()).split(“,”)
total = float(data[1] + float(data[2])
total = str(total)
x=str(data[0])
f2. write (x+ “ “ + total + “\n”)
f1 .close( )
f2 . close( )
h
Kala ,40,60
j a
Bala ,80,50
Sa
Rajah ,90,60
nra;epuiy epiwNtw;wpa gpd;dh; Nfhg;G output.txt ,y; cs;slf;fk; fhl;lg;gLk; tpjk; ahJ?
m
(1) Kala 100,0 Bala 130,0 Rajah 150,0 (2) kala 100 Bala 130 Rajah 150
ls a
(3) Kala 100.0 (4) Kala 100
A
Bala 130.0 Bala 130
Rajah 150.0 Rajah 150
Write a python code to read data file and write the Name and total in output file
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 8 of 15
Python - Revision AL-ICT
A. a=[2,3.01,-1,0,'Lathan'];print(a)
B. a=\
[2,3.01,-1,0,'Lathan']
print(a)
C. print(len([2,3.01,-1,0,'Lathan']))
D. a=100
b=20
if a>b:
None
else:
pass
h
(1) A, B (2) B, C (3) A, C, D (4) B,C, D (5) A, B, C, D
Saj a
The pass statement in Python is used when a statement is required syntactically but
you do not want any command or code to execute. The pass statement is a null
operation; nothing happens when it executes.
m
None is just a value that commonly is used to signify 'empty', or 'no value here
A ls a
1. gpd;tUk; marks.txt vDk; ghlf;Nfhg;G (Text file) xU tFg;gpYs;s khztu;nga;u;fisAk;
mtu;fs; %d;W ghlq;fspy; ngw;w Gs;spfisAk; nfhz;Ls;sJ. xt;nthW khzupdJk;
ruhrupg;Gs;spfisf; fzpj;J khztu;fsJ ngau; kw;Wk; rhuhrupg;Gs;spfis result.txt vDk;
ghlf;Nfhg;gpy; (fPNo glj;jpy; fhl;bAs;sthW) gjpaNtz;Lk;.
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 9 of 15
Python - Revision AL-ICT
f=open('marks.txt','r')
f1=open('result.txt','w')
name=f.readline()
while (name!=""):
m1=int(f.readline())
m2=int(f.readline())
m3=int(f.readline())
average=round((m1+m2+m3)/3,2) rounded to 2 decimal place
#print('Name= ',name,'Average= ',average)
f1.write('Name:'+name+'Average:'+str(average)+"\n")
name=f.readline()
f.close()
f1.close()
h
only string can be written in file
j a
While (name!=””) ; until end of the text
Sa
2. gaduplk; VNjDk; 10 ,yf;fq;fis cs;sPlhfg; ngw;W mtw;wpd; $l;Lj;njhifia
m
ntspaPlhfg; ngw;Wf;nfhs;Stjw;fhd gha;w;rr
; l; Nfhl;Lg;glj;ij tiue;J> mjw;Fupa
ls a
igj;jhd; nra;epuiy vOJf.
counter=1
A
sum=0
while counter<=10:
n=int(input('Enter any Integer : '))
sum=sum+n
counter=counter+1
print ("Total : ",sum)
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 10 of 15
Python - Revision AL-ICT
3. gaduplk; VNjDk; 10 ,yf;fq;fis cs;sPlhfg; ngw;W (Neu; KO vz;kw;Wk; kiw KO
vz;) Neu; vz;fspd; $l;Lj;njhifia NtuhfTk; kiw vz;fspd; $l;Lj;njhifia
NtuhfTk; ntspaPlhfg; ngw;Wf;nfhs;Stjw;fhd igj;jhd; nra;epuiy vOJf.
j ah
Sa
4. jug;gl;l List=[5,-25,7,-6,8,-68,-9,12,85,-6,10] ,y; ,Ue;J Neu; vz;fis xU list ,w;Fk; kiw
vz;fis NtNuhu; List ,w;Fk; NtWgLj;Jtjw;fhd igj;jhd; nra;epuy; xd;iw vOJf.
ls a m
#Seperate -ve and +ve numbers from a list
List=[5,-25,7,-6,8,-68,-9,12,85,-6,10]
A
p=[]
n=[]
for x in List:
if x>0:
p.append(x)
else:
n.append(x)
print('Positive Numbers: ',p)
print('Negative Numbaers: ',n)
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 11 of 15
Python - Revision AL-ICT
List=[5,-25,7,-6,8,-68,-9,12,85,-6,10]
p=[]
psum=0
n=[]
nsum=0
for x in List:
if x>0:
p.append(x)
psum=psum+x
else:
n.append(x)
nsum=nsum+x
print('Positive Numbers: ',p,' Total = ',psum)
h
print('Number of elements: ',len(p))
j a
print('Negative Numbaers: ',n,' otal = ',nsum)
Sa
print('Number of elements: ',len(n))
ls a m
6. 10 ,yf;fq;fis gaduplk; ,Ue;J ngw;W> mtw;Ws; 20 I tpl ngupa ,yf;fq;fis xU
List ,Yk; 20 my;yJ 20 I tplf; $ba ,yf;fq;fis NtNuhu; List ,Yk; Nru;jJ
A
; mtw;iwf;
fhl;rpg;gLj;Jtjw;fhd igj;jhd; nra;epuy; xd;iw vOJf.
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 12 of 15
Python - Revision AL-ICT
7. f=['Mathematics','Science','English'] vDk; List ,Ys;s ghlq;fspy; fhzg;gLk; vOj;Jf;fspd;
vz;zpf;ifiaf; fz;L fhl;rpg;gLj;Jtjw;fhd igj;jhd; nra;epuy; xd;iw vOJf.
h
X=(L[:11]) print(x,end="")
j a
for a in X:
Sa
print(a,end=(""))
ls a m
9. Fwpj;j xU ghlrhiyapYs;s khztu;fis ,y;y tpisahl;Lg; Nghl;b xd;wpw;fhf
mtu;fspd; Rl;nlz;fis mbg;gilahff; nfhz;L %d;W ,y;yq;fSf;F tifg;gLj;j
Ntz;Lk;. ,jw;fhf xU igj;jd; nra;epuiy tbtikf;FkhW ePu; Nfl;fg;gl;Ls;sPu;.
A
• xU khztdpd; Rl;nlz;iz (KOntz;zhFk;) cs;sPL nra;J 3 My; tFf;Fk;
NghJ kPjp 0 ngwg;gLkhapd; mtu; ROSE ,y;yj;jpw;Fk; kPjp 1 ngwg;gLkhapd; mtu;
LOTUS ,y;yj;jpw;Fk; kPjp 2 ngwg;gLkhapd; mtu; JASMINE ,y;yj;jpw;Fk; njupT
nra;ag;gLthu;.
• fPNo jug;gl;l Kiwapy; khztu;fspd; Rl;nlz; mtu;fspd; ,y;yj;Jld; 'house.txt' vDk;
ghlf;Nfhitapy; (text file) ePq;fs; gjpTnra;a Ntz;Lk;.
index_no_1 – house 1 Example:
index_no_2 – house 2
index_no_3 – house 3
………………………...
,q;F>
index_no_x : x vDk; khztdpd; Rl;nlz;> x = 1,2,3,4…..,n
house_xy : x vDk; khztdpd; ,y;yk;> y = 1,2,3
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 13 of 15
Python - Revision AL-ICT
f=open("house.txt","w")
a=int(input('Enter index number: '))
while a!=0:
if a%3==0:
f.write(str(a) + '-' + 'ROSE'+ '\n')
else:
if a%3==1:
f.write(str(a) + '-' + 'LOTUS'+'\n')
else:
f.write(str(a) + '-' + 'JASMIN'+'\n')
a=int(input('Enter index number:'))
f.close()
h
(a) fPotUk; igj;jhd; nra;epuypy; gad;gLj;jg;gl;Ls;s “While” fl;lisf;Fg;gjpyhf “for”
j a
fl;lisiag; gad;gLj;jp ,r;nra;epuiy nraw;gLj;j KbAkh? ckJ tpilia
Sa
epahag;gLj;Jf.
m
while ch=='y':
ls a
print('your choice is y')
ch=input('Do you want to continue ("y" or "n") ')
A
NO, Don’t know no of repetition
(i) print(list(‘Education’))
(ii) a=[10,20,30]
a.sort()
a.reverse()
print(a)
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 14 of 15
Python - Revision AL-ICT
11. gj;J KO vz;fis gaduplk; ,Ue;J ngw;W mtw;Ws; ,ul;il vz;fis khj;jpuk;
“even_number.txt” vDk; ghlf;Nfhg;gpy; gjpT nra;tjw;fhd gha;r;rw; Nfhl;Lg; glj;ijAk;
igj;jd; nra;epuiyAk; vOJf.
f=open('even_Number.txt','w')
c=0
while c<10:
n=int(input('Enter an Integer :'))
if n%2==0:
f.write(str(n)+'\n')
c=c+1
f.close()
h
&. 5.00 ck; Vidatw;wpw;F Xu;myfpw;F &. 10.00 ck; fl;lzk; tpjpf;fg;gLk;.
a
(a) tPl;L cupikahsupd; ,yf;fk;> kpd; khdpapd; Kd;ida kw;Wk; jw;Nghija thrpg;G
j
vd;gd jug;gLk; NghJ tPl;Lcupikahsuplk; ,Ue;J mwtpl Ntz;ba nkhj;jf;
Sa
fl;lzj;ijf;fzpg;gjw;Fg; gad;gLj;jf;$ba newpKiwia tifFwpf;Fk;
gha;r;rw;Nfhl;Lg;glj;ij tiuf.
(b) NkNy (a) apy; ePq;fs; je;j newpKiwia Python nra;epuy; nkhopapy; FwpKiwahf;Ff.
ls a m
vy;yhr; nry;YgbahFk; vLNfhs;fisAk; (vitAk; ,Ug;gpd;) Fwpg;gpLf.
(c) tPl;L cupikahsu; ,yf;fk;> khdp thrpg;Gfs;> mwtpl Ntz;ba nkhj;jf; fl;lzk; vd;gd
,Uf;Fk; “deb.txt” vDk; ghlf;Nfhg;gpd; ,Wjpapy;vOJtjw;Fupa Python rhu;gpid
A
cUthf;Ff.
def wf(houseNo,rpast,rpresent,charge):
f=open("deb.txt","a")
print(houseNo,rpast,rpresent,charge,file=f,sep=",")
f.close()
-------------------------------------------------OR
def wf(houseNo,rpast,rpresent,charge):
f=open("deb1.txt","a")
f.write(str(houseNo)+" "+str(rpast)+" "+ str(rpresent)+" "+str(charge))
f.close()
M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 15 of 15