SlideShare a Scribd company logo
Python - Part 1
Pramodya Kodikara
පයිතන්
භාෂාව
Pramodya Kodikara To join online classes 070 200 62 63
පයිතන්
භාෂාව
Pramodya Kodikara To join online classes 070 200 62 63
4
ICT with
පයිතන් භාෂාව හැදින්වීම
❑ උසස් මට්ටෙම් පරිගණක භාෂාවකි.
❑ අර්ථ වින්‍යාසක භාෂාවකේ ෙවේ.(Interpreted)
❑ වස්තු මත පද පදනම් වූ භාෂාවකි. (object oriented
language- Polymorphism, Inheritance, Encapsulation)
❑ ආධුනිකයන්ට සරලව අවෙබෝධ කරගත් හැකි
භාෂාවකි .
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)Pramodya Kodikara To join online classes 070 200 62 63
5
ICT with
පයිතන් භාෂාෙවේ ඉතිහාසය
❑ 1980 දශකෙයේ දශකෙයේ අග
භාගෙයේදී Guido Van Rossum
විසින් ෙමය නිර්මාණය කර
ඇත.
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
6
ICT with
❑ https://www.python.org/downloads/
පයිතන් භාෂාව ස්ථාපනය කිරීම
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
7
ICT with
Ex 1
print("Hello world")
Hello world
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
8
ICT with
Ex 2 a = “Hello World”
print (a)
a= “Hello World” ;print (a)
ප්‍රකාශන(statement)
a= “Hello World”
print 
(a)
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
9
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
ICT with
• පයිතන් භාෂාව හඳුන්වාදීම සඳහා ඇවිරැණු පද භාවිත ෙවේ.
• ඒ ඒ කාර්යන්ට අදාළව පද හඳුන්වා දී ඇත.
• ෙම්වා හඳුන්වනයන් identifier ෙලස ෙයාදාගත ෙනාහැක .
• ඇවිරැණු පද පරිගණක භාෂාෙවන් භාෂාවට ෙවනස් ෙවේ.
ඇවිරැනු පද (Reserved
words)
10OL (Regency-Matale) AL (Isurusara - Matale)
11
ICT with
නියත
❖ නියතයන් හිදී වරින්වර අගයන් ෙවනස් ෙනාෙවේ.
❖ යම් අගයක් ලබා දුන් විට එය ස්ථිරව ගබඩා කර ගනී.
❖ උදාහරණ s1Mark= 70
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
12
ICT with
විචල්‍ය
ප්‍රධාන මතකෙයේ දත්ත තාවකාලිකව ගබඩා කිරීමට
විචල්‍ය ෙයාදා ගැෙන්.
විචල්‍ය වල ලකේෂණ නම්
❑ නාමය ෙවනස් ෙනාකර වරින් වර ෙවනස් අගයන් සහිත දත්ත
රඳවා තබා ගැනීමට හැකිවීම.
❑ අලුෙතන් දත්තයක් ලබා ලබාගන්නා විට, ෙපර රඳවාෙගන තිබූ
දත්ත ඉවත් කරමින් එක් වරකට එක් දත්තයක් පමණක් රඳවා
ගැනීම.
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
13
ICT with
විචල්‍ය ආකාර ෙදකකි.
• ස්ථානීය විචල්‍යයන්
විචල්‍ය හඳුන්වා දුන් අවස්ථාෙවේ පමණක් භාවිතා කළ හැකි විචල්‍ය
ස්ථානීය විශාල ෙලස හැඳින්ෙවේ
• විශ්ව විචල්‍යයන්
ෙමම විචල්‍යයන් හඳුන්වා දුන් අවස්ථාෙවේ දී පමණක් ෙනාව ඕනෑම
ස්ථානයක භාවිත කළ හැක
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
14
ICT with
විචල්‍ය නම් කිරීම හා සම්බන්ධ රීති
▪ python භාෂාෙවේ වචන reserved word භාවිත ෙනාකළ යුතුය.
▪ පළමු අකුර ෙලස අංක භාවිතා කළ ෙනාහැක. නමුත් පළමු
අකුෙරන් පසුව අංක භාවිත කළ හැක
▪ @,$,% යන සංෙක්ත භාවිත කළ ෙනාහැක .
▪ විචල්‍ය නාමය තුල හිස්තැන් තැබිය ෙනාහැක
▪ “_”(underscore) ආරම්භෙයේ දී භාවිත කළ හැක
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
15
ICT with
විචල්‍ය නාමයන් සඳහා වලංගු ෙවේද ?
8value
Marks
@Address
_name
For
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
16
ICT with
දත්ත ප්‍රරෑප- Data Type
සංඛ්‍යා දත්ත
ප්‍රරෑප
භාවිතය සංඛ්‍යා දත්ත
ප්‍රරෑප
භාවිතය
String අක්ෂර සහිත
දත්ත වර්ග
සඳහා
int දශමස්ථාන
රහිත පූර්ණ
සංඛ්‍යා සඳහා
Long අෂ්ටමය, ෂඩ්
දශමය
සංඛ්‍යාසඳහා
float දශමස්ථාන
සහිත සංඛ්‍යා
සඳහා
complex විවිධ වර්ගෙයේ
සංඛ්‍යා දත්ත
සඳහා
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
17
ICT with
Type Function
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
x=10
Y=10.245
print(type(x))
print(type(Y))
Type function මගින් දත්ත ප්‍රරෑපය ෙපන්වයි.
18
ICT with
කාරක ප්‍රවර්ග (Operator Categories)
කාරකය භාවිතය
+ සංඛ්‍යා එකතු කිරීම
- සංඛ්‍යා අඩු කිරීම
* සංඛ්‍යා ගුණ කිරීම
/ සංඛ්‍යා ෙබදීම
// ෙබදීම මගින් ලබා ගන්නා පූර්ණ
අගය ෙපන්වීම
% ෙබදීෙමන් ලැෙබන ඉතිරිය
** බලය ලබා ගැනීම
ගණිතමය කාරක arithmetic operator
category
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
19
ICT with
කාරක ප්‍රවර්ග (Operator Categories)
කාරකය භාවිතය
< වම්පස ඇති අගය කුඩා ද යන්න
<= වම්පස ඇති අගය කුඩා ද සමාන ද
යන්න
> වම්පස ඇති අගය විශාල ද යන්න
>= වම්පස ඇති අගය විශාල ද සමාන ද
යන්න
== ෙදපස අගයන් සමාන ෙවේ ද යන්න
!= ෙදපස අගයන් අසමාන ෙවේ ද යන්න
සම්බන්ධක කාරක-
relational operators category
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
20
ICT with
බිටුසාරිත
කාරක
Bitwise Operatorකාරකය භාවිතය
& AND
| OR
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
21
ICT with
බිටුසාරිත කාරක
උදාහරණ
Bitwise Operator Examples
කාරකය භාවිතය
& AND
| OR
print (11 & 15)
1011 1111
1011
Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
22
ICT with
බිටුසාරිත කාරක
උදාහරණ
Bitwise Operator Examples
කාරකය භාවිතය
& AND
| OR
print (11 | 15)
1011 1111
1111
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
Thank you
23
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
24
ICT with
Python හි Quotation
භාවිතය>>> word=‘Sri Lanka '
>>> word1=" Kandy “
>>>print('''word1''')
>>> print(word)
Sri Lanka
>>> print(word1)
Kandy
>>>print('''word1''')
word1
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
25
ICT with
Python Comments භාවිතය
>>> #this is a comment
>>> x=10 #value 10 is assigned to variable x
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
26
ICT with
▪ පරිගණක මතකය තුළ තාවකාලිකව දත්ත තැන්පත්
කිරීම සඳහා විචල්යයන් ෙයාදා ගනී.
▪ ෙමහි ආෙදේශ කරන අගයන් අනුව (values) අදාල දත්ත
ප්‍රරෑපය ගලපා ගනිමින් දත්ත ගබඩා කර ගනී . ෙමහි දී
= ලකුණ ෙයාදා ගැෙන්
දත්ත ප්‍රරෑප(data types)
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
27
ICT with
>>> name="john“ #string value
>>> age=17 #integer value
>>> distance=100.00 #floating point value
>>> print(name)
John
>>> print(age)
17
>>> print(distance)
100.0
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
28
úp,H lsysmhlgu tlu w.h wdfoaY
lsÍuo mhs;ka mrs.Kl NdIdj
u.ska isÿ l< yelsh'
a=b=c=10
print(a,b,c)
10 10 10
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
29
කාරක ප්‍රමුඛතාවය
(Operator Procedure)
()
**
/*%//
+-
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
30
කාරක ප්‍රමුඛතාවය
(Operator Procedure)
()
**
/*%//
+-
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
31
කාරක ප්‍රමුඛතාවය
(Operator Procedure)
()
**
/*%//
+-
2019 -44 (100 // 3) % 4 | 8
2018- 35 (5**2) // 3^4
2016 - 42 x=3-4*6/3 + 12/4* 3
2014-42 10-4 * 3/2 - 5
2013-16 10-3*2+2.0
2012-19
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
32
>>> 2 + 2
>>> 5 + 4 - 3
ගණිතමය කාරක (arithmetic operators)
භාවිතය
>>> 2 * (3 + 4)
>>> 10 / 2
4
6
14
0.5
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
33
Floats
>>> 3/4
0.75
>>> 7.2765000
7.2765
>>> 7.27688000
7.27688
>>> 5.2765660
5.276566
>>> 7.2765999999
7.2765999999
34
Errors හදුනා
ගැනීම
SyntaxError: unexpected indent
ZeroDivisionError
35
ZeroDivisionError යන්නට ලක්වීමට
ෙහේතුවන ෙලස හිස්තැන් පුරවන්න
>>> (17 + 94) / (-8+ __)
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
36
>>> 1/3
SyntaxError: unexpected indent
Answer should - (0.3333333333333333...)
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
37
ICT with
Fill in the blank with the output of this code.
>>> 1 + 2 + 3 + 4+5.0 + 6
________
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
38
ICT with
>>> 2**6
>>> 9 ** (1/2)
64
3.0
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
39
ICT with
Ex
input (“Enter your marks here: ”)
යතුරැ පුවරැෙවන් ආදානය
marks= input (“Enter your marks here: ”)
marks= int(input (“Enter your marks here: ”))
marks= float(input (“Enter your marks here: ”))
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
40
ICT with
වරණය
වරණයට අදාලව භාවිත කරන විධානයන්
❑ if statement
❑ if – else statement
❑ nested if statement
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
41
ICT with
Syntax
කාරක රීතිය
if expression :
statement(s)
marks=int(input("Enter Marks:- "))
if (marks > 50):
print ("Pass")
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
42
ICT with
Syntax
කාරක රීතිය
if expression :
statement(s)
else :
statement(s)
marks=int( input("Enter Marks:=" ))
if (marks > 50):
print("Pass")
else :
print("Fail")
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
43
ICT with
Syntax
කාරක රීතිය if expression1 :
statement(s)
elif expression2 :
statement(s)
elif expression3 :
statement(s)
else:
statement(s)
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
44
ICT with
marks=int(input("Enter your marks:= "))
if marks>=75:
print("Your grade is A")
elif marks>=65:
print("Your grade is B")
elif marks>=55:
print("Your grade is C")
elif marks>=35:
print("Your grade is S")
else:
print("Your grade is F")
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
Python - Part 2
Pramodya Kodikara
46
ICT with
1-10 දක්වා සංඛ්‍යා මුද්‍රණය කිරීම සදහා
ෙක්තය ලියා දක්වන්න.
Method 1
x=1
while(x<=10):
print(x)
x=x+1
Method 2
x=1
while x<=10:
print(x)
x=x+1
A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
Pramodya Kodikara To join online classes 070 200 62 6347
ICT with
while සමග else භාවිතය
0-10 දක්වා සංඛ්‍යා වල 10 අඩු සංඛ්‍යා සහ 10ට අඩු ෙනාවන සංඛ්‍යා
ෙලස මුද්‍රණය කිරීමට අදාල python ෙක්තය ලියා දක්වන්න
count = 0
while count <10:
print (count,"is less than 10 ")
count = count+1
else:
print(count,"is not less than 10")
48
ICT with
Take 10 integers from keyboard using loop and print their
average value on the screen.
අංක 10 ආදානය කර ඒ්වාෙයේ සාමාන්‍ය අගය මුද්‍රණය කිරීමට
අදාල python ෙක්තය ලියා දක්වන්න.
Pramodya Kodikara To join online classes 070 200 62 63
49
ICT with
sum = 0
i = 10
while i>0:
num = int(input( "Enter a number"))
sum = sum + num
i = i-1
print ("average is",sum/10.0)
sum = 0
i = 10
while i>0:
num = int(input( "Enter a number"))
sum = sum + num
i = i-1
print ("average is",sum/10.0)
sum = 0
i = 10
while i>0:
num = int(input( "Enter a number"))
sum = sum + num
i = i-1
print ("average is",sum/10.0)
sum = 0
i = 1
while i<=10:
num = int(input( "Enter a number"))
sum = sum + num
i = i+1
print ("average is",sum/10.0)
Pramodya Kodikara To join online classes 070 200 62 63
50
ICT with
Print the following patterns using loop :
පහත දැක්ෙවන රටා මුද්‍රණය කිරීම සදහා python ෙක්ත ලියා දක්වන්න.
a.
*
**
***
****
b.
*
***
*****
***
*
c.
1010101
10101
101
1
Pramodya Kodikara To join online classes 070 200 62 63
51
ICT with
i = 1
while i<=4:
print ("*"*i)
i = i+1
#b
i = 1
j = 2
while i>=1:
a = " "*j+"*"*i+" "*j
print(a)
i = i+2
j = j-1
if i>5:
break
i = 3
j = 1
while i>=1:
a = " "*j+"*"*i+" "*j
print(a)
i = i-2
j = j+1
num=int(input(“Enter number of rows”))
i = 1
while i<=num:
print ("*"*i)
i = i+1
#b
i = 1
j = 2
while i>=1:
a = " "*j+"*"*i+" "*j
print(a)
i = i+2
j = j-1
if i>5:
break
i = 3
j = 1
while i>=1:
a = " "*j+"*"*i+" "*j
print(a)
i = i-2
52
ICT with
Print multiplication table of 24, 50 and 29 using loop.
i = 1
while i<=10:
print ("24 x",i,24*i)
i = i+1
Pramodya Kodikara To join online classes 070 200 62 63
53
ICT with
ෙදන ලද සංඛ්‍යාවක අනුකක්‍රිමනය ෙසවීම සදහා ෙක්තය ලියා දක්වන්න
1! = 1
0! = 1 ෙවේ.
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
___________________________________
Factorial of any number n is represented by n!
and is equal to 1*2*3*....*(n-1)*n. E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 1
Write a program to calculate factorial of a given number.
Pramodya Kodikara To join online classes 070 200 62 63
54
ICT with
number = int(input("Enter number "))
fac = 1
if number == 0:
print ("1")
else:
while number>=1:
fac = fac*number
number = number-1
print (fac)
Pramodya Kodikara To join online classes 070 200 62 63
55
for loop python
Syntax
for iterating_var in range :
statements
ප්‍රකාශන(statement) එකක් ෙහෝ වැඩි ගණනක් නිශ්චිත
වාර ගණනක් තුළ පුනර්කරණය සඳහා ෙමය භාවිත
ෙකෙර්.
පුනර්කරණය වන වාර ගණන නිශ්චිතව දන්නා විට
පමණක් ෙමය භාවිත කළ හැක.
ෙමය කික්‍රියාකාරී වන අවස්ථා නම්
1. දී ඇති ලයිස්තුවක් මත
2. අගයන් පරාසය මත
56
for loop
for a in range(end number)
for a in range(10) → a හි අගය 0-10 දක්වා පරාසය
තුල ෙවේ.
for a in range(start number, end number)
for a in range(5,10) → a හි අගය 5-10 දක්වා පරාසය
තුල ෙවේ.
for a in range(start number, end number, step value)
for a in range(5,10,2) → a හි අගය 5-10 දක්වා
පරාසය තුල 2න් 2 අගයන් ෙවේ. ඒනම් 5,7,9 ෙලස ෙවේ.
57
ඔබෙගේ නම පස් වතාවකේ මුද්‍රණය
කිරීම සඳහා python ෙකේතය ලියා
දකේවන්න.
for name in range(5):
name="pramodya Kodikara"
print(name)
58
5 සිට 10 දකේවා සංඛ්‍යා මුද්‍රණය කර
ගැනීමට අදාල ෙකේතය ලියා දකේවන්න.
for num in range(5,10):
print(num)
ආරම්භක අගය සහ
අවසාන අගය ෙවනස්
කරගන්නා ආකාරය
Pramodya Kodikara To join online classes 070 200 62 63
59
එෙක් සිට දහය දක්වා ඔත්ෙත් සංඛ්‍යා මුද්‍රණය
කිරීමට අදාල python ෙක්තය ලියා දක්වන්න
for num in range(1,10,2):
print(num)
සංඛ්‍යා අතර
පරාසය
එෙක් සිට දහය දක්වා ඉරටේෙටේ සංඛ්‍යා මුද්‍රණය
කිරීමට අදාල python ෙක්තය ලියා දක්වන්න
Pramodya Kodikara To join online classes 070 200 62 63
60
Activity - For Loop
01) 0-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා
දක්වන්න.
02) 1-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා
දක්වන්න.
03) 1-10 දක්වා තුෙන් ගුණාකාර මුදුණයට අදාල python
ෙක්තය ලියා දක්වන්න.
Pramodya Kodikara To join online classes 070 200 62 63
61
Activity - For Loop
01) 0-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න.
For num in range(5):
print(num )
01) 1-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න.
For num in range(1,5):
01) 1-0 දක්වා තුෙන් ගුණාකාර මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න.
For num in range(3,10,3):
Pramodya Kodikara To join online classes 070 200 62 63
62
අක්ෂර සහිත දත්ත කාණ්ඩයක
ආරම්භෙයේ සිට අවසානය වන ෙතක්
අක්ෂර මුද්‍රණය කිරීම
for a in "Kandy":
print(a)
Pramodya Kodikara To join online classes 070 200 62 63
63Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තු (Data list)
names=["Malithi", 'Maala', "Nirmala" , 'Kamani']
64Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තු (Data list) මුද්‍රණය කිරීම
names=[88,56,75,88,11]
print(names[4])
names=["Malithi", 'Mala', "Nirmala" , 'Kamani']
print (names[0], names[1])
names=["Malithi", 'Mala', "Nirmala" , 'Kamani']
(names[0:2])
names=["Malithi", 'Mala', "Nirmala" , 'Kamani']
print(names[0:4])
names=["Malithi", 'Mala', "Nirmala" , 'Kamani']
for a in names:
print(a)
65Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තු (Data list) මුද්‍රණය කිරීම
names=[88,56,75,88,11]
print(names[2:]) output [75,88,11] ෙදෙකේ සිට අවසානය ෙතකේ
names=[88,56,75,88,11]
print(names[-2]) 88 -1 සිට දකුෙණේ සිට වමට කියවයි.
66Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තු (Data list) එකතු කිරීම
marks1 =[88,56,75,88,11]
marks2=[55,66,80]
total=marks1+marks2
print(total)
67Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තු (Data list) ගුණනය
කිරීම
marks1 =[88,56,75,88,11]
mul=marks1*3
print(mul)
68Pramodya Kodikara To join online classes 070 200 62 63
දත්ත ලැයිස්තුවක (Data list) අවම
අගය සහ විශාල අගය ෙසවීම
marks1 =[88,56,75,88,11]
print(min(marks1))
marks1=[88,56,75,88,11]
print(max(marks1))
69
දත්ත ලැයිස්තුවකේ (Data list) සමග
for loop භාවිතය
names=["Malithi", 'Mala', "Nirmala" , 'Kamani']
for a in names:
print(a)
Pramodya Kodikara To join online classes 070 200 62 63
70
Print the following pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
lastNumber = 6
for row in range(1, lastNumber):
for column in range(1, row + 1):
print(column, end=' ')
print("")
71
Accept number from user and calculate the sum of all
number between 1 and given number
For example user given 10 so the output should be 55
sum = 0
n = int(input("Please enter number n"))
for i in range(1, n+1, 1):
sum += i
print("Sum is: ", sum)
Pramodya Kodikara To join online classes 070 200 62 63
72
Print multiplication table of given number
n = 2
for i in range(1, 11, 1):
product = n*i
print(product)
Pramodya Kodikara To join online classes 070 200 62 63
73
පුනර්කරණ පාලනයන් (Loop
controls)
Break - loop තුල Break ෙයදූ විට
loop එෙකන් ඉවත්වීම සිදුෙවේ.
Continue- loop තුල continue
ෙයදීෙමන් එම ස්ධානෙයන් පහලට
ක්‍රමෙලේඛනය ධාවනය ෙනාවී නැවත
loop එෙකේ මුල සිට ධාවනය වීම
පටන් ගනී
activity walata lab sheets ගන්න java වල
Pramodya Kodikara To join online classes 070 200 62 63
74Pramodya Kodikara To join online classes 070 200 62 63
a=0
b=5
While a<b:
print(a)
a=a+1
continue
print(“Inside the loop”)
print (“out of the while”)
Continue
75Pramodya Kodikara To join online classes 070 200 62 63
a=0
b=5
While a<b:
print(a)
a=a+1
break
print(“Inside the loop”)
print (“out of the while”)
Break
76Pramodya Kodikara To join online classes 070 200 62 63
Part 3
77Pramodya Kodikara To join online classes 070 200 62 63
78Pramodya Kodikara To join online classes 070 200 62 63
79Pramodya Kodikara To join online classes 070 200 62 63
80Pramodya Kodikara To join online classes 070 200 62 63
81Pramodya Kodikara To join online classes 070 200 62 63
82Pramodya Kodikara To join online classes 070 200 62 63
83Pramodya Kodikara To join online classes 070 200 62 63
84Pramodya Kodikara To join online classes 070 200 62 63
85Pramodya Kodikara To join online classes 070 200 62 63
86Pramodya Kodikara To join online classes 070 200 62 63
87Pramodya Kodikara To join online classes 070 200 62 63
88Pramodya Kodikara To join online classes 070 200 62 63
89Pramodya Kodikara To join online classes 070 200 62 63
90Pramodya Kodikara To join online classes 070 200 62 63
91Pramodya Kodikara To join online classes 070 200 62 63
92Pramodya Kodikara To join online classes 070 200 62 63
93Pramodya Kodikara To join online classes 070 200 62 63
94Pramodya Kodikara To join online classes 070 200 62 63
95Pramodya Kodikara To join online classes 070 200 62 63
96Pramodya Kodikara To join online classes 070 200 62 63
97Pramodya Kodikara To join online classes 070 200 62 63
98Pramodya Kodikara To join online classes 070 200 62 63
99Pramodya Kodikara To join online classes 070 200 62 63
100Pramodya Kodikara To join online classes 070 200 62 63
101Pramodya Kodikara To join online classes 070 200 62 63
102Pramodya Kodikara To join online classes 070 200 62 63
103Pramodya Kodikara To join online classes 070 200 62 63
104Pramodya Kodikara To join online classes 070 200 62 63
105Pramodya Kodikara To join online classes 070 200 62 63
106Pramodya Kodikara To join online classes 070 200 62 63
107Pramodya Kodikara To join online classes 070 200 62 63
108Pramodya Kodikara To join online classes 070 200 62 63
109Pramodya Kodikara To join online classes 070 200 62 63
110Pramodya Kodikara To join online classes 070 200 62 63
111Pramodya Kodikara To join online classes 070 200 62 63
112Pramodya Kodikara To join online classes 070 200 62 63
113Pramodya Kodikara To join online classes 070 200 62 63
114
115
116
THANK YOU!

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Python Note Part 1

  • 1. Python - Part 1 Pramodya Kodikara
  • 4. 4 ICT with පයිතන් භාෂාව හැදින්වීම ❑ උසස් මට්ටෙම් පරිගණක භාෂාවකි. ❑ අර්ථ වින්‍යාසක භාෂාවකේ ෙවේ.(Interpreted) ❑ වස්තු මත පද පදනම් වූ භාෂාවකි. (object oriented language- Polymorphism, Inheritance, Encapsulation) ❑ ආධුනිකයන්ට සරලව අවෙබෝධ කරගත් හැකි භාෂාවකි . Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)Pramodya Kodikara To join online classes 070 200 62 63
  • 5. 5 ICT with පයිතන් භාෂාෙවේ ඉතිහාසය ❑ 1980 දශකෙයේ දශකෙයේ අග භාගෙයේදී Guido Van Rossum විසින් ෙමය නිර්මාණය කර ඇත. Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 6. 6 ICT with ❑ https://www.python.org/downloads/ පයිතන් භාෂාව ස්ථාපනය කිරීම Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 7. 7 ICT with Ex 1 print("Hello world") Hello world Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 8. 8 ICT with Ex 2 a = “Hello World” print (a) a= “Hello World” ;print (a) ප්‍රකාශන(statement) a= “Hello World” print (a) Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 9. 9 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63 ICT with • පයිතන් භාෂාව හඳුන්වාදීම සඳහා ඇවිරැණු පද භාවිත ෙවේ. • ඒ ඒ කාර්යන්ට අදාළව පද හඳුන්වා දී ඇත. • ෙම්වා හඳුන්වනයන් identifier ෙලස ෙයාදාගත ෙනාහැක . • ඇවිරැණු පද පරිගණක භාෂාෙවන් භාෂාවට ෙවනස් ෙවේ. ඇවිරැනු පද (Reserved words)
  • 10. 10OL (Regency-Matale) AL (Isurusara - Matale)
  • 11. 11 ICT with නියත ❖ නියතයන් හිදී වරින්වර අගයන් ෙවනස් ෙනාෙවේ. ❖ යම් අගයක් ලබා දුන් විට එය ස්ථිරව ගබඩා කර ගනී. ❖ උදාහරණ s1Mark= 70 Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 12. 12 ICT with විචල්‍ය ප්‍රධාන මතකෙයේ දත්ත තාවකාලිකව ගබඩා කිරීමට විචල්‍ය ෙයාදා ගැෙන්. විචල්‍ය වල ලකේෂණ නම් ❑ නාමය ෙවනස් ෙනාකර වරින් වර ෙවනස් අගයන් සහිත දත්ත රඳවා තබා ගැනීමට හැකිවීම. ❑ අලුෙතන් දත්තයක් ලබා ලබාගන්නා විට, ෙපර රඳවාෙගන තිබූ දත්ත ඉවත් කරමින් එක් වරකට එක් දත්තයක් පමණක් රඳවා ගැනීම. Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 13. 13 ICT with විචල්‍ය ආකාර ෙදකකි. • ස්ථානීය විචල්‍යයන් විචල්‍ය හඳුන්වා දුන් අවස්ථාෙවේ පමණක් භාවිතා කළ හැකි විචල්‍ය ස්ථානීය විශාල ෙලස හැඳින්ෙවේ • විශ්ව විචල්‍යයන් ෙමම විචල්‍යයන් හඳුන්වා දුන් අවස්ථාෙවේ දී පමණක් ෙනාව ඕනෑම ස්ථානයක භාවිත කළ හැක Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 14. 14 ICT with විචල්‍ය නම් කිරීම හා සම්බන්ධ රීති ▪ python භාෂාෙවේ වචන reserved word භාවිත ෙනාකළ යුතුය. ▪ පළමු අකුර ෙලස අංක භාවිතා කළ ෙනාහැක. නමුත් පළමු අකුෙරන් පසුව අංක භාවිත කළ හැක ▪ @,$,% යන සංෙක්ත භාවිත කළ ෙනාහැක . ▪ විචල්‍ය නාමය තුල හිස්තැන් තැබිය ෙනාහැක ▪ “_”(underscore) ආරම්භෙයේ දී භාවිත කළ හැක Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 15. 15 ICT with විචල්‍ය නාමයන් සඳහා වලංගු ෙවේද ? 8value Marks @Address _name For Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 16. 16 ICT with දත්ත ප්‍රරෑප- Data Type සංඛ්‍යා දත්ත ප්‍රරෑප භාවිතය සංඛ්‍යා දත්ත ප්‍රරෑප භාවිතය String අක්ෂර සහිත දත්ත වර්ග සඳහා int දශමස්ථාන රහිත පූර්ණ සංඛ්‍යා සඳහා Long අෂ්ටමය, ෂඩ් දශමය සංඛ්‍යාසඳහා float දශමස්ථාන සහිත සංඛ්‍යා සඳහා complex විවිධ වර්ගෙයේ සංඛ්‍යා දත්ත සඳහා Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 17. 17 ICT with Type Function Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale) x=10 Y=10.245 print(type(x)) print(type(Y)) Type function මගින් දත්ත ප්‍රරෑපය ෙපන්වයි.
  • 18. 18 ICT with කාරක ප්‍රවර්ග (Operator Categories) කාරකය භාවිතය + සංඛ්‍යා එකතු කිරීම - සංඛ්‍යා අඩු කිරීම * සංඛ්‍යා ගුණ කිරීම / සංඛ්‍යා ෙබදීම // ෙබදීම මගින් ලබා ගන්නා පූර්ණ අගය ෙපන්වීම % ෙබදීෙමන් ලැෙබන ඉතිරිය ** බලය ලබා ගැනීම ගණිතමය කාරක arithmetic operator category Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 19. 19 ICT with කාරක ප්‍රවර්ග (Operator Categories) කාරකය භාවිතය < වම්පස ඇති අගය කුඩා ද යන්න <= වම්පස ඇති අගය කුඩා ද සමාන ද යන්න > වම්පස ඇති අගය විශාල ද යන්න >= වම්පස ඇති අගය විශාල ද සමාන ද යන්න == ෙදපස අගයන් සමාන ෙවේ ද යන්න != ෙදපස අගයන් අසමාන ෙවේ ද යන්න සම්බන්ධක කාරක- relational operators category Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 20. 20 ICT with බිටුසාරිත කාරක Bitwise Operatorකාරකය භාවිතය & AND | OR Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 21. 21 ICT with බිටුසාරිත කාරක උදාහරණ Bitwise Operator Examples කාරකය භාවිතය & AND | OR print (11 & 15) 1011 1111 1011 Pramodya Kodikara OL (Regency-Matale) AL (Isurusara - Matale)
  • 22. 22 ICT with බිටුසාරිත කාරක උදාහරණ Bitwise Operator Examples කාරකය භාවිතය & AND | OR print (11 | 15) 1011 1111 1111 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 23. Thank you 23 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 24. 24 ICT with Python හි Quotation භාවිතය>>> word=‘Sri Lanka ' >>> word1=" Kandy “ >>>print('''word1''') >>> print(word) Sri Lanka >>> print(word1) Kandy >>>print('''word1''') word1 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 25. 25 ICT with Python Comments භාවිතය >>> #this is a comment >>> x=10 #value 10 is assigned to variable x A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 26. 26 ICT with ▪ පරිගණක මතකය තුළ තාවකාලිකව දත්ත තැන්පත් කිරීම සඳහා විචල්යයන් ෙයාදා ගනී. ▪ ෙමහි ආෙදේශ කරන අගයන් අනුව (values) අදාල දත්ත ප්‍රරෑපය ගලපා ගනිමින් දත්ත ගබඩා කර ගනී . ෙමහි දී = ලකුණ ෙයාදා ගැෙන් දත්ත ප්‍රරෑප(data types) A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 27. 27 ICT with >>> name="john“ #string value >>> age=17 #integer value >>> distance=100.00 #floating point value >>> print(name) John >>> print(age) 17 >>> print(distance) 100.0 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 28. 28 úp,H lsysmhlgu tlu w.h wdfoaY lsÍuo mhs;ka mrs.Kl NdIdj u.ska isÿ l< yelsh' a=b=c=10 print(a,b,c) 10 10 10 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 29. 29 කාරක ප්‍රමුඛතාවය (Operator Procedure) () ** /*%// +- A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 30. 30 කාරක ප්‍රමුඛතාවය (Operator Procedure) () ** /*%// +- A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 31. 31 කාරක ප්‍රමුඛතාවය (Operator Procedure) () ** /*%// +- 2019 -44 (100 // 3) % 4 | 8 2018- 35 (5**2) // 3^4 2016 - 42 x=3-4*6/3 + 12/4* 3 2014-42 10-4 * 3/2 - 5 2013-16 10-3*2+2.0 2012-19 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 32. 32 >>> 2 + 2 >>> 5 + 4 - 3 ගණිතමය කාරක (arithmetic operators) භාවිතය >>> 2 * (3 + 4) >>> 10 / 2 4 6 14 0.5 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 33. 33 Floats >>> 3/4 0.75 >>> 7.2765000 7.2765 >>> 7.27688000 7.27688 >>> 5.2765660 5.276566 >>> 7.2765999999 7.2765999999
  • 35. 35 ZeroDivisionError යන්නට ලක්වීමට ෙහේතුවන ෙලස හිස්තැන් පුරවන්න >>> (17 + 94) / (-8+ __) A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 36. 36 >>> 1/3 SyntaxError: unexpected indent Answer should - (0.3333333333333333...) A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 37. 37 ICT with Fill in the blank with the output of this code. >>> 1 + 2 + 3 + 4+5.0 + 6 ________ A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 38. 38 ICT with >>> 2**6 >>> 9 ** (1/2) 64 3.0 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 39. 39 ICT with Ex input (“Enter your marks here: ”) යතුරැ පුවරැෙවන් ආදානය marks= input (“Enter your marks here: ”) marks= int(input (“Enter your marks here: ”)) marks= float(input (“Enter your marks here: ”)) A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 40. 40 ICT with වරණය වරණයට අදාලව භාවිත කරන විධානයන් ❑ if statement ❑ if – else statement ❑ nested if statement A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 41. 41 ICT with Syntax කාරක රීතිය if expression : statement(s) marks=int(input("Enter Marks:- ")) if (marks > 50): print ("Pass") A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 42. 42 ICT with Syntax කාරක රීතිය if expression : statement(s) else : statement(s) marks=int( input("Enter Marks:=" )) if (marks > 50): print("Pass") else : print("Fail") A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 43. 43 ICT with Syntax කාරක රීතිය if expression1 : statement(s) elif expression2 : statement(s) elif expression3 : statement(s) else: statement(s) A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 44. 44 ICT with marks=int(input("Enter your marks:= ")) if marks>=75: print("Your grade is A") elif marks>=65: print("Your grade is B") elif marks>=55: print("Your grade is C") elif marks>=35: print("Your grade is S") else: print("Your grade is F") A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 45. Python - Part 2 Pramodya Kodikara
  • 46. 46 ICT with 1-10 දක්වා සංඛ්‍යා මුද්‍රණය කිරීම සදහා ෙක්තය ලියා දක්වන්න. Method 1 x=1 while(x<=10): print(x) x=x+1 Method 2 x=1 while x<=10: print(x) x=x+1 A/L ICT O/L ICT Online / Regency -Matale /Isurusara - Matale Pramodya Kodikara 070 200 62 63
  • 47. Pramodya Kodikara To join online classes 070 200 62 6347 ICT with while සමග else භාවිතය 0-10 දක්වා සංඛ්‍යා වල 10 අඩු සංඛ්‍යා සහ 10ට අඩු ෙනාවන සංඛ්‍යා ෙලස මුද්‍රණය කිරීමට අදාල python ෙක්තය ලියා දක්වන්න count = 0 while count <10: print (count,"is less than 10 ") count = count+1 else: print(count,"is not less than 10")
  • 48. 48 ICT with Take 10 integers from keyboard using loop and print their average value on the screen. අංක 10 ආදානය කර ඒ්වාෙයේ සාමාන්‍ය අගය මුද්‍රණය කිරීමට අදාල python ෙක්තය ලියා දක්වන්න. Pramodya Kodikara To join online classes 070 200 62 63
  • 49. 49 ICT with sum = 0 i = 10 while i>0: num = int(input( "Enter a number")) sum = sum + num i = i-1 print ("average is",sum/10.0) sum = 0 i = 10 while i>0: num = int(input( "Enter a number")) sum = sum + num i = i-1 print ("average is",sum/10.0) sum = 0 i = 10 while i>0: num = int(input( "Enter a number")) sum = sum + num i = i-1 print ("average is",sum/10.0) sum = 0 i = 1 while i<=10: num = int(input( "Enter a number")) sum = sum + num i = i+1 print ("average is",sum/10.0) Pramodya Kodikara To join online classes 070 200 62 63
  • 50. 50 ICT with Print the following patterns using loop : පහත දැක්ෙවන රටා මුද්‍රණය කිරීම සදහා python ෙක්ත ලියා දක්වන්න. a. * ** *** **** b. * *** ***** *** * c. 1010101 10101 101 1 Pramodya Kodikara To join online classes 070 200 62 63
  • 51. 51 ICT with i = 1 while i<=4: print ("*"*i) i = i+1 #b i = 1 j = 2 while i>=1: a = " "*j+"*"*i+" "*j print(a) i = i+2 j = j-1 if i>5: break i = 3 j = 1 while i>=1: a = " "*j+"*"*i+" "*j print(a) i = i-2 j = j+1 num=int(input(“Enter number of rows”)) i = 1 while i<=num: print ("*"*i) i = i+1 #b i = 1 j = 2 while i>=1: a = " "*j+"*"*i+" "*j print(a) i = i+2 j = j-1 if i>5: break i = 3 j = 1 while i>=1: a = " "*j+"*"*i+" "*j print(a) i = i-2
  • 52. 52 ICT with Print multiplication table of 24, 50 and 29 using loop. i = 1 while i<=10: print ("24 x",i,24*i) i = i+1 Pramodya Kodikara To join online classes 070 200 62 63
  • 53. 53 ICT with ෙදන ලද සංඛ්‍යාවක අනුකක්‍රිමනය ෙසවීම සදහා ෙක්තය ලියා දක්වන්න 1! = 1 0! = 1 ෙවේ. 4! = 1*2*3*4 = 24 3! = 3*2*1 = 6 2! = 2*1 = 2 ___________________________________ Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.- 4! = 1*2*3*4 = 24 3! = 3*2*1 = 6 2! = 2*1 = 2 Also, 1! = 1 0! = 1 Write a program to calculate factorial of a given number. Pramodya Kodikara To join online classes 070 200 62 63
  • 54. 54 ICT with number = int(input("Enter number ")) fac = 1 if number == 0: print ("1") else: while number>=1: fac = fac*number number = number-1 print (fac) Pramodya Kodikara To join online classes 070 200 62 63
  • 55. 55 for loop python Syntax for iterating_var in range : statements ප්‍රකාශන(statement) එකක් ෙහෝ වැඩි ගණනක් නිශ්චිත වාර ගණනක් තුළ පුනර්කරණය සඳහා ෙමය භාවිත ෙකෙර්. පුනර්කරණය වන වාර ගණන නිශ්චිතව දන්නා විට පමණක් ෙමය භාවිත කළ හැක. ෙමය කික්‍රියාකාරී වන අවස්ථා නම් 1. දී ඇති ලයිස්තුවක් මත 2. අගයන් පරාසය මත
  • 56. 56 for loop for a in range(end number) for a in range(10) → a හි අගය 0-10 දක්වා පරාසය තුල ෙවේ. for a in range(start number, end number) for a in range(5,10) → a හි අගය 5-10 දක්වා පරාසය තුල ෙවේ. for a in range(start number, end number, step value) for a in range(5,10,2) → a හි අගය 5-10 දක්වා පරාසය තුල 2න් 2 අගයන් ෙවේ. ඒනම් 5,7,9 ෙලස ෙවේ.
  • 57. 57 ඔබෙගේ නම පස් වතාවකේ මුද්‍රණය කිරීම සඳහා python ෙකේතය ලියා දකේවන්න. for name in range(5): name="pramodya Kodikara" print(name)
  • 58. 58 5 සිට 10 දකේවා සංඛ්‍යා මුද්‍රණය කර ගැනීමට අදාල ෙකේතය ලියා දකේවන්න. for num in range(5,10): print(num) ආරම්භක අගය සහ අවසාන අගය ෙවනස් කරගන්නා ආකාරය Pramodya Kodikara To join online classes 070 200 62 63
  • 59. 59 එෙක් සිට දහය දක්වා ඔත්ෙත් සංඛ්‍යා මුද්‍රණය කිරීමට අදාල python ෙක්තය ලියා දක්වන්න for num in range(1,10,2): print(num) සංඛ්‍යා අතර පරාසය එෙක් සිට දහය දක්වා ඉරටේෙටේ සංඛ්‍යා මුද්‍රණය කිරීමට අදාල python ෙක්තය ලියා දක්වන්න Pramodya Kodikara To join online classes 070 200 62 63
  • 60. 60 Activity - For Loop 01) 0-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. 02) 1-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. 03) 1-10 දක්වා තුෙන් ගුණාකාර මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. Pramodya Kodikara To join online classes 070 200 62 63
  • 61. 61 Activity - For Loop 01) 0-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. For num in range(5): print(num ) 01) 1-5 දක්වා සංඛ්‍යා මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. For num in range(1,5): 01) 1-0 දක්වා තුෙන් ගුණාකාර මුදුණයට අදාල python ෙක්තය ලියා දක්වන්න. For num in range(3,10,3): Pramodya Kodikara To join online classes 070 200 62 63
  • 62. 62 අක්ෂර සහිත දත්ත කාණ්ඩයක ආරම්භෙයේ සිට අවසානය වන ෙතක් අක්ෂර මුද්‍රණය කිරීම for a in "Kandy": print(a) Pramodya Kodikara To join online classes 070 200 62 63
  • 63. 63Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තු (Data list) names=["Malithi", 'Maala', "Nirmala" , 'Kamani']
  • 64. 64Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තු (Data list) මුද්‍රණය කිරීම names=[88,56,75,88,11] print(names[4]) names=["Malithi", 'Mala', "Nirmala" , 'Kamani'] print (names[0], names[1]) names=["Malithi", 'Mala', "Nirmala" , 'Kamani'] (names[0:2]) names=["Malithi", 'Mala', "Nirmala" , 'Kamani'] print(names[0:4]) names=["Malithi", 'Mala', "Nirmala" , 'Kamani'] for a in names: print(a)
  • 65. 65Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තු (Data list) මුද්‍රණය කිරීම names=[88,56,75,88,11] print(names[2:]) output [75,88,11] ෙදෙකේ සිට අවසානය ෙතකේ names=[88,56,75,88,11] print(names[-2]) 88 -1 සිට දකුෙණේ සිට වමට කියවයි.
  • 66. 66Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තු (Data list) එකතු කිරීම marks1 =[88,56,75,88,11] marks2=[55,66,80] total=marks1+marks2 print(total)
  • 67. 67Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තු (Data list) ගුණනය කිරීම marks1 =[88,56,75,88,11] mul=marks1*3 print(mul)
  • 68. 68Pramodya Kodikara To join online classes 070 200 62 63 දත්ත ලැයිස්තුවක (Data list) අවම අගය සහ විශාල අගය ෙසවීම marks1 =[88,56,75,88,11] print(min(marks1)) marks1=[88,56,75,88,11] print(max(marks1))
  • 69. 69 දත්ත ලැයිස්තුවකේ (Data list) සමග for loop භාවිතය names=["Malithi", 'Mala', "Nirmala" , 'Kamani'] for a in names: print(a) Pramodya Kodikara To join online classes 070 200 62 63
  • 70. 70 Print the following pattern 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 lastNumber = 6 for row in range(1, lastNumber): for column in range(1, row + 1): print(column, end=' ') print("")
  • 71. 71 Accept number from user and calculate the sum of all number between 1 and given number For example user given 10 so the output should be 55 sum = 0 n = int(input("Please enter number n")) for i in range(1, n+1, 1): sum += i print("Sum is: ", sum) Pramodya Kodikara To join online classes 070 200 62 63
  • 72. 72 Print multiplication table of given number n = 2 for i in range(1, 11, 1): product = n*i print(product) Pramodya Kodikara To join online classes 070 200 62 63
  • 73. 73 පුනර්කරණ පාලනයන් (Loop controls) Break - loop තුල Break ෙයදූ විට loop එෙකන් ඉවත්වීම සිදුෙවේ. Continue- loop තුල continue ෙයදීෙමන් එම ස්ධානෙයන් පහලට ක්‍රමෙලේඛනය ධාවනය ෙනාවී නැවත loop එෙකේ මුල සිට ධාවනය වීම පටන් ගනී activity walata lab sheets ගන්න java වල Pramodya Kodikara To join online classes 070 200 62 63
  • 74. 74Pramodya Kodikara To join online classes 070 200 62 63 a=0 b=5 While a<b: print(a) a=a+1 continue print(“Inside the loop”) print (“out of the while”) Continue
  • 75. 75Pramodya Kodikara To join online classes 070 200 62 63 a=0 b=5 While a<b: print(a) a=a+1 break print(“Inside the loop”) print (“out of the while”) Break
  • 76. 76Pramodya Kodikara To join online classes 070 200 62 63 Part 3
  • 77. 77Pramodya Kodikara To join online classes 070 200 62 63
  • 78. 78Pramodya Kodikara To join online classes 070 200 62 63
  • 79. 79Pramodya Kodikara To join online classes 070 200 62 63
  • 80. 80Pramodya Kodikara To join online classes 070 200 62 63
  • 81. 81Pramodya Kodikara To join online classes 070 200 62 63
  • 82. 82Pramodya Kodikara To join online classes 070 200 62 63
  • 83. 83Pramodya Kodikara To join online classes 070 200 62 63
  • 84. 84Pramodya Kodikara To join online classes 070 200 62 63
  • 85. 85Pramodya Kodikara To join online classes 070 200 62 63
  • 86. 86Pramodya Kodikara To join online classes 070 200 62 63
  • 87. 87Pramodya Kodikara To join online classes 070 200 62 63
  • 88. 88Pramodya Kodikara To join online classes 070 200 62 63
  • 89. 89Pramodya Kodikara To join online classes 070 200 62 63
  • 90. 90Pramodya Kodikara To join online classes 070 200 62 63
  • 91. 91Pramodya Kodikara To join online classes 070 200 62 63
  • 92. 92Pramodya Kodikara To join online classes 070 200 62 63
  • 93. 93Pramodya Kodikara To join online classes 070 200 62 63
  • 94. 94Pramodya Kodikara To join online classes 070 200 62 63
  • 95. 95Pramodya Kodikara To join online classes 070 200 62 63
  • 96. 96Pramodya Kodikara To join online classes 070 200 62 63
  • 97. 97Pramodya Kodikara To join online classes 070 200 62 63
  • 98. 98Pramodya Kodikara To join online classes 070 200 62 63
  • 99. 99Pramodya Kodikara To join online classes 070 200 62 63
  • 100. 100Pramodya Kodikara To join online classes 070 200 62 63
  • 101. 101Pramodya Kodikara To join online classes 070 200 62 63
  • 102. 102Pramodya Kodikara To join online classes 070 200 62 63
  • 103. 103Pramodya Kodikara To join online classes 070 200 62 63
  • 104. 104Pramodya Kodikara To join online classes 070 200 62 63
  • 105. 105Pramodya Kodikara To join online classes 070 200 62 63
  • 106. 106Pramodya Kodikara To join online classes 070 200 62 63
  • 107. 107Pramodya Kodikara To join online classes 070 200 62 63
  • 108. 108Pramodya Kodikara To join online classes 070 200 62 63
  • 109. 109Pramodya Kodikara To join online classes 070 200 62 63
  • 110. 110Pramodya Kodikara To join online classes 070 200 62 63
  • 111. 111Pramodya Kodikara To join online classes 070 200 62 63
  • 112. 112Pramodya Kodikara To join online classes 070 200 62 63
  • 113. 113Pramodya Kodikara To join online classes 070 200 62 63
  • 114. 114
  • 115. 115