You are on page 1of 16

G.C.

E (A/L)

ICT
j ah
mSa
Als a SEC
Kandy

M.T.M Aslam Sajah


(BSc, PGD in Edu, PGD in IT)
T.P/ WhatsApp: 0718110533
Python - Revision AL-ICT
Flowchart & Pseudocode Start
1. jug;gl;l gha;r;rw;Nfhl;Lg;glj;jpd; tUtpisT ahJ?
X=1
(1) 2 , 4 , 6 , 8 , 10
(2) 1 ,3 , 5 , 7 , 9
(3) 1 , 2 , 3 , 4 , 5 , 6 , 7, 8 , 9 Print X
(4) 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
(5) 1 , 3 , 5 , 7 , 9 , 11
X=X+2

? 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

(1) 2 jlitfs; nraw;gLk;


M=6
(2) 3 jlitfs; nraw;gLk;
Until M<4 (3) 4 jlitfs; nraw;gLk;
M=M-2 (4) 6 jlitfs; nraw;gLk;
Loop (5) xU jlitNaDk; nraw;gl khl;lhJ

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

(1) 1 jlit khj;jpuk; nraw;gLk; begin


(2) 3 jlitfs; nraw;gLk; n=7
m=4
(3) 5 jlitfs; nraw;gLk; do while m>5
(4) xUNghJk; KbtilahJ m=m-n
(5) xU jlitNaDk; nraw;gl khl;lhJ
end while
7. jug;gl;l gha;r;rl;Nghl;Lg;glj;jpdhy; gpwg;gpf;fg;gLk; ntspaPL
ahJ?
(1) 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
(2) 0, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 Start
(3) 1 , 3 , 5 , 7 , 9
(4) 1 , 3 , 5 , 7 , 9 , 11
n=1
(5) 1 , 3 , 5 , 7 , 9 , 10 n=n+2

8. gpd;tUk; Nghypf;Fwpapd; tUtpisT ahJ? Yes


n=<10 Display n

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

9. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ? Begin


X =1
(1) 1 Y= 3
(2) 3 Do
(3) 27 Z=x * Y
(4) 30 X=X+1
(5) 33 Until x>10
Display Z
10. gpd;tUk; Nghypf;Fwpapd; ntspaPL ahJ? 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

12. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?


Begin
a=5
(1) 5 b=5
While a = b
(2) 6
a = a+2
(3) 10
b= b+4

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

15. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?

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

16. jug;gl;l Nghypf;Fwpapd; tUtpisT ahJ?

(1) 0, 1, 1, 2, 3, 5, 8, 13, 21 x=0


(2) 1, 1, 2, 3, 5, 8, 13, 21, 34 y=1

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

20. jug;gl;l igj;jd; nra;epuypd; tUtpisT ahJ? a=0


while a<5:
(1) 2 4 6 (2) 3 5 7 a=a+2
(3) 2 3 4 (4) 4 5 6 print(a+1,end=' ')
(5) 0 2 4

21. jug;gl;l igj;jhd; epuiy nraw;gLj;Jk; NghJ ngwg;gLk; tUtpisT ahJ?

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, " ")

(1) 1 2 3 4 End of value i 4 (2) 1 2 3 4 End of value i 5 (3) 1 1 1 1 End of value i 4


(4) 1 2 3 4 5 End of value 5 (5) 1 2 3 4 5 End of value 6

23. gpd;tUtdtw;Ws; igj;jhd; khwpfis tiuaiu nra;jypy; njhlupay uPjpahf (syntacaly)


jtuhdJ?
A - x=2;y=5
B - x=y=z=10,15
C - a,b,c=2,4,’Leena’
D - x,y,z=10,(4,7)

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;

 ; is a separator , not a terminator. can use as an end of a line


 x = y = z = 2,3,4  x,y,z = (2,3,4) tuple

24. gpd;tUk; igjd; nra;epuypd; tUtpisT ahJ ?


x=[3,6,8,5,4,10]
print (x[0:4:-1])
(1) [5,8,6,3] (2) [ ] (3) [10] (4) [3,6,8,5,4] (5) [3,4,10]

 0  4 cannot by -1

25. gpd;tUk; igj;jhd; $w;Wf;fisf; fUJf


x={2,3,’ict’,10,0}
y=”[2,3,4,[‘I’,’c’,’t’],10,100]”
z=5,6
Nkw;Fwpj;j nra;epuy; $w;Wf;fis epiuNtw;wpa gpd;du; X,Y,Z Mfpa khwpfspd; tiffs;

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

27. gpd;tUk; igjd; nra;epuypd; tpisT ahJ ?


x = set(‘apple’)
y = set(applicant)
print (x ^ y)

(1){t,n,c,p,e} ( 2 ) {`a`,`p`,`t`} (3) {`e`,`r`,t} (4) {`e`} (5) {`i`,`t`,`c`,`e`,`n`}

 & - Union | - Intersection ^ - Symmetric deference

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

29. jug;gl;l igj;jhd; epuiy nraw;gLj;Jk; NghJ ngwg;gLk; tUtpisT ahJ?

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)

(5) [`d`, `ceptiveness`]

 This command split from 2 orderly 2

31. gpd;tUk; igjhd; $w;Wf;fisf; fUJf.


A- $ This is main program
B- # This program is written by Leena
C- a = 1 #Value 1 assigned to variable a
D - #a = 1 Value 1 assigned to variable a
,tw;Ws; njhlhpay; hPjpapy; rhpahf vOjg;;gl;Ls;s Fwpg;Giufs;; (Comments) vit?

(1) A, B kl;Lk;; (2) A, C kl;Lk;; (3) B, C, D kl;Lk;;


(4) A, C, D kl;Lk;; (5) A, B, C, D ahTk;

32. gpd;tUk; igjd; $w;Wf;fSy; rupahdJ vJ?


(1) a = [12, 4, “2’, -3 ] (2) a = [[],{},(),] (3) a = b = 2,3,4
(4) i = 01234 (5) a = true

M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 7 of 15
Python - Revision AL-ICT

33. gpd;tUk; igjd; nra;epuiyf; fUJf.

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( )

Nkw;gb input.txt Nfhg; g py; cs;s juTfs; fPNo jug;gl;Ls;sJ.

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

(5) Kala 40,60,100


Bala 80,50,130
Rajan 90,60,150

 Write a python code to read data file and write the Name and total in output file

data file  data.txt


Python code
Aashif, 100,50,75
Leena, 250,75,85 f1=open('data.txt','r')
f2=open('output.txt','w')
Sara, 50,75,100
for x in f1:
data=(x.strip()).split(',')
total=float(data[1])+int(data[2])+int(data[3])
output file  output.txt total=str(total)
#print(total)
Aashif Total = 225.0 f2.write(data[0]+'\t'+'Total = '+total+'\n')
Leena Total = 410.0
f1.close()
Amani Total = 225.0 f2.close()

M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 8 of 15
Python - Revision AL-ICT

34. gpd;tUk; igjhd; nra;epuy; $w;Wf;fSy; rupahdJ/rupahdit

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

Part 2 - Structures and Essay

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;.

(a) Nkw;gb gpur;rpizf;fhd newpKiwia gha;r;rl; Nfhl;Lg;glk; xd;wpy; jUf.


(b) NkNy ckJ newpKiwf;fhd igj;jhd; nra;epuiy vOJf.

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.

#Input 10 integers and diplay +ve total and -ve Total


counter=1
psum=0
nsum=0
while counter<=10:
n=int(input('Enter any Integer : '))
if n>0:
psum=psum+n
else:
nsum=nsum+n
counter=counter+1
print ("Negative total : ",nsum,'\n',"Positive total : ",psum)

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)

5. 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;jp mt;ntz;fspd; $l;Lj;njhifiaAk;
ntt;Ntuhff; fhl;rpg;gLj;Jtjw;fhd igj;jhd; nra;epuiy vOJf.

M.T.M Aslam Sajah (BSc, PGD in Edu, PGD in IT) TP/ WhatApp: 0718110533 Page 11 of 15
Python - Revision AL-ICT

#Seperate -ve and +ve numbers from alist


#Display totals seperately

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.

#Get 10 numbers from user


#seperate >=20 and <20
#display them
h=[]
l=[]
for x in range(1,10):
n=int(input("Enter a number: "))
if n>=20:
h.append(n)
else:
l.append(n)
print(h)
print(l)

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.

#Display No of charactors in the elements f=['Mathematics','Science','English']


f=['Mathematics','Mcience','English'] for i in f:
for i in f: count=0
print(i ,'is:',len(i)) for j in i:
count=count+1
print(i,'is:',count)

8. "Information and communication technology" vDk; trdj;jpy; ,Ue;J “Information” vDk;


nrhy;iy khj;jpuk; ngw;W fhl;rpg;gLj;Jtjw;fhd igj;jhd;nra;epuy;xd;iw vOJf.

x="Information and communication


technlogy" s="Python programming"
L=list(x) for x in s[0:6:]:

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

xt;nthU khztupdJk; Rl;nlz; jdpj;jdpahf tpirg;gyifapD}lhf cs;sPL


nra;ag;gLtNjhL Rl;nlz;Zf;F ngWkhdk; 0 I cs;sPL nra;Ak; NghJ nra;epuy; KbTf;F
tUjy; Ntz;Lk;.

(a) Nkw;gb fzpdpr; nra;epuYf;Fj; Njitahd rfy cs;sPLfisAk;


vjpu;ghu;f;fg;gLk; tUtpistpidAk; vOJf.
(b) gha;r;rw;Nfhl;Lg; glk; xd;iwg; gad;gLj;jp Nkw;gb nra;epuYf;fhd newpKiwnahd;iw
Kd;itf;Ff.
(c) ePu; Kd;itj;j gha;r;rw;Nfhl;Lg; glj;ij mKy;gLj;Jtjw;fhd igjd; nra;epuy; xd;iw vOJf.

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()

10. gpd;tUk; tpdhf;fSf;F tpil jUf.

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.

ch=input('Enter "y" or "n" ')

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

(b) fPo;tUk; igj;jhd; nra;epuypd; Jyq;fs; ahJ?

(i) print(list(‘Education’))

 ['E', 'd', 'u', 'c', 'a', 't', 'i', 'o', 'n']

(ii) a=[10,20,30]
a.sort()
a.reverse()
print(a)

 [30, 20, 10]

(iii) import time


time.sleep(10)
print('welcome')
 The text ‘welcome’ will be displayed after 10 second

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()

12. tPLfspy; kpd;Efu;tpw;Fr; nYj;j Ntz;ba fl;lzk; ghtizahsu; gad;gLj;Jk; kpd;


myFfspd; vz;zpf;ifapd; mbg;gilapy; jq;fpAs;sJ. Kjy; 64 myFfSf;F> Xu; myfpw;F

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.

hno=input("Enter House No : ")


rfinal=int(input("Enter Final meter Reading : "))
rnow=int(input("Enter Present meter Reading : "))
usedunit=rnow-rfinal
if usedunit>64:
payment=64*5.00+(usedunit-64)*10.00
else:
payment=usedunit*5.00
print(payment)

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

You might also like