Adsense

OUO Banner

Latest Posts

Python2 Lesson 11

Lesson 1 ၾကည့္ရန္ link  >> Click Here
Lesson 2 ၾကည့္ရန္ link  >> Click Here
Lesson 3 ၾကည့္ရန္ link  >> Click Here
Lesson 4 ၾကည့္ရန္ link >> Click Here
Lesson 5 ၾကည့္ရန္ link >> Click Here

Lesson 6 ၾကည့္ရန္ link >> Click Here
Lesson 7 ၾကည့္ရန္ link >> Cl
ick Here
Lesson 8 ၾကည့္ရန္ link >> Click Here
Lesson 9 ၾကည့္ရန္ link >> Click Here
Lesson 10 ၾကည့္ရန္ link >> Click Here
...........................................................................
Python Programming
မဂၤလာပါခင္ဗ်ာ။ ဒီေန႔အတြက္ သင္ခန္းစာသစ္ မစတင္ခင္မွာ မေန႔ကသင္ခန္းစာကို ျပန္ဆက္ခ်င္ပါတယ္။
ပံုစံသစ္တစ္မ်ိဳးေလးနဲ႔ပါပဲ။ ဖန္ရွင္သစ္ တည္ေဆာက္ျခင္းနဲ႔ ဆက္စက္မႈရွိတဲ့ Default Value တည္ေဆာက္ျခင္းပါ။
 ကဲ စျပီေနာ္။
......
Python ကို terminal ကေန ေခၚျပီး
>>> def kmn(x,y,z):
...  print x
...  print y
...  print z
... ခုလို သတ္မွတ္ေပးလိုက္ပါတယ္။ enter ၂ခ်က္ဆင္းျပီး ေနာက္တစ္လိုင္းကူးလိုက္ပါတယ္။
>>> kmn('Khit Minnyo', 29, 'Learning Python')
Khit Minnyo
29
Learning Python
kmn လို႔ သတ္မွတ္လိုက္တဲ့ ထဲမွာ ေဒတာေတြကို ျဖည့္သြင္းေပးလိုက္ပါတယ္။ ခုေတာ့ ဒီလိုပံုစံေလး ထြက္လာတာကို ေတြ႕ရပါျပီေနာ္။
ဒါေတာ့ ရွင္းပါတယ္။ x, y, z တို႔ ေနရာမွာ သူတို႔အတြက္ အစားဝင္လာတဲ့ တန္ဖိုးေတြကို စီေပးလိုက္တာေလးပါပဲ။
ကဲ ဒါဆို ေမးစရာရွိလာျပန္ျပီ။ ေဒတာေတြက သံုးေလးခုထက္ ပိုခဲ့ရင္ (အမ်ားႀကီးျဖစ္ေနရင္) ဘယ္လိုလုပ္ၾကမလဲေပါ့။
အဲသည္အတြက္ေတာ့ def သတ္မွတ္ခဲ့စဥ္ကတည္းက ပံုစံတစ္မ်ိဳးနဲ႔ သတ္မွတ္ခဲ့ရမွာျဖစ္ပါတယ္။
....
>>> def kmn(*unknown):
...  print unknown
... ဒီပံုစံေလး တည္ေဆာက္လိုက္ျပီေနာ္။ အတိအက် မသိရတာမို႔လို႔ unknown ေပါ့။ * ေတာ့ အေရးႀကီးပါတယ္။ မက်န္ခဲ့နဲ႔ေပါ့။
.......တည္ေဆာက္ျပီးျပီဆို စမ္းၾကည့္ရေအာင္ဗ်
>>> kmn ('Zaw Zaw', 25, 'Ma Ma', 22, 'Aung Aung', 'Hla Hla', 23, 24, 25, 26, 27, 28, 1000)
('Zaw Zaw', 25, 'Ma Ma', 22, 'Aung Aung', 'Hla Hla', 23, 24, 25, 26, 27, 28, 1000)
ကဲ ခုဆို အမ်ားႀကီးထည့္လည္း အေျဖ ထြက္လာပါျပီ......
.......
......
ေနာက္တစ္ခု ေသခ်ာၾကည့္ပါ။ တူသလိုလိုနဲ႔ မတူတာေတြ႔ရပါမယ္။ ေသခ်ာၾကည့္ျပီး ကြာျခားခ်က္ကို မွတ္ထားပါ။
ဒီတစ္ခါေတာ့ ဖန္ရွင္အမည္ကို တစ္ခုခု ေျပာင္းသံုးရေအာင္။ ေတာ္ၾကာ ဒီတစ္မ်ိဳးပဲ ျဖစ္ေနမယ္
....
>>> def kkk (name, *age):
...  print name
...  print age
...
kkk ဆိုတဲ့ ဖန္ရွင္ေလးကို ကြ်န္ေတာ္ တည္ေဆာက္လိုက္ပါတယ္။ ေရးပံုကေလးကို သတိထားေစခ်င္ပါတယ္။
...
>>> kkk ('Aung Aung',1,2,3,4,5)
Aung Aung
(1, 2, 3, 4, 5)
>>>အထက္ပါအတိုင္း ေခၚၾကည့္လိုက္ပါတယ္။ ကိန္းေတြကို မိမိေရးလိုသည္ထိဆက္ေရးႏိုင္ပါတယ္ဗ်။ စမး္ၾကည့္ၾကဖို႔ လိုအပ္ပါတယ္။
.............
..............
ကဲ ဒီတစ္ခါေတာ့ ပံုမွန္အသြင္ေတြနဲ႔ ကြဲေအာင္ ခပ္ဆန္းဆန္းေလး ဖန္တီးခြင့္ေပးမယ္။
ဘာလုပ္မွာလို႔ ႀကိဳမေျပာေသးဘဲ ေနာက္ဆံုးမွ လုပ္ရင္းသိလာတာကို လိုခ်င္လို႔ အထူးအေထြ မေျပာေတာ့ဘူးလို႔ ဆံုးျဖတ္ထားလိုက္ပါတယ္။
ကဲ Desktop ေပၚမွာ ေနရာလြတ္ကေလးမွာ R-click ကေလးႏွိပ္ျပီး New Folder ကေန d13 ဆိုတဲ့ folder ေလးတစ္ခု ဖန္တီးလိုက္ရေအာင္။ အားလံုး လုပ္ႏိုင္မယ္လို႔ ယူဆပါတယ္။
ျပီးရင္ leafpad ေလးဖြင့္ျပီး
print "This is a small program of day 13."
readfile = open ('read.txt', 'r')
print readfile.read()
အထက္ပါ စာေၾကာင္းေလးေတြပဲ ရိုက္ျပီး ခုန folder ထဲမွာ reader.py ဆိုတဲ့ နာမည္နဲ႔  Save ထားပါ။
ျပီးရင္ ပိတ္ထားလိုက္လို႔ ရပါျပီ။ ကဲ ေနာက္တစ္ခါ  leafpad အသစ္ ထပ္ဖြင့္ရေအာင္။ ဒီတစ္ခါေတာ့ text ေတြ အေနနဲ႔ ပဲ ေရးမွာမို႔ မိမိတို႔ ႏွစ္သက္ရာ ေရးထားႏိုင္ပါတယ္။
ကြ်န္ေတာ္ကေတာ့ အဂၤလိပ္ကဗ်ာတစ္ပုဒ္ ေရးထားပါတယ္။
Lost Innocence

© Michaela Remmel

Published on April 2015

Wind whistling,
Snow glistening,
We try not to,
But we're all listening.

Loud screams,
Bad dreams,
It's very far,
But close it seems.

Sad day,
Lost our way,
All we can do,
Is simply pray.

Innocence gone,
Life no longer long,
We may not know,
But we're all doing wrong.

Joy lost,
The Holocaust,
We look to see,
Hearts covered in frost.

Wars fought,
Sins taught,
Making mistakes,
Hoping not to be caught.

Not taking blame,
Pushing for fame,
As advanced as we are,
We're still all untamed.

Too much pride,
Needing a guide,
We will deny it,
But behind lies we hide.

Hurting others,
Betraying brother,
Many forgetting,
To appreciate mothers.

Lies are fed,
Filling heart and head,
Through all of these years,
Innocent blood has been shed.

Children abandoned,
Lonely and stranded,
We're all wasting the life
That we have been handed.

Taking from the poor,
We're loving no more,
Fight to be free,
End up starting a war.

People starting fights,
No longer enjoying the sights,
While mere mortals are taking
Our God given rights.

Soldiers killed,
Void can't be filled,
Pay close attention,
For pure souls have been tilled.

Need to find peace,
Work together like geese,
But greatest of all,
The hate needs to cease.

အထက္ပါအတိုင္း leafpad အသစ္မွာေရးလိုက္ျပီး ခုန d13 ဆိုတဲ့ folder ထဲမွာပဲ read.txt ဆိုတဲ့ နာမည္နဲ႔  Save ထားလိုက္ပါတယ္။
သတိထားရမွာက read.txt လို႔ နာမည္ေရးျပီး Save ရမွာေနာ္။
......................................................
ျပီးရင္ ပိတ္ထားလိုက္လို႔လည္း ရပါျပီ။ ကဲ ဒီခါေတာ့ terminal ကေန cd command နဲ႔ တစ္ဆင့္ခ်င္းဖြင့္တဲ့ manual ကို မသံုးေတာ့ဘဲ ေနာက္တစ္နည္းေပါ့။
ဖြင့္ရေအာင္။ ခုန Desktop မွာ ထားခဲ့တဲ့ d13 folder ကို ပံုမွန္အတိုင္းပဲ ဖြင့္လိုက္ပါ။ ျပီးရင္ ပြင့္လာတဲ့ထဲမွာ ခုန ဖိုင္ ၂ခု ရွိေနပါမယ္။ ျပန္စစ္ၾကည့္ပါ။
reader.py နာမည္နဲ႔ တစ္ဖိုင္၊ read.txt ဆိုတဲ့နာမည္နဲ႔ တစ္ဖိုင္ ၂ဖိုင္ေပါ့။ ဟုတ္ျပီဆိုရင္ အဲသည္ folder ထဲမွာပဲ လြတ္တဲ့ေနရာမွာ R-click ပါ။ ျပီးရင္ open in terminal ကိုႏွိပ္ျပီးဖြင့္ပါ။
သက္ဆိုင္ရာ folder ထဲကို ေရာက္ျပီးသား ရပါျပီ။
python ဖိုင္ကို  RUN ဖို႔အတြက္ Terminal မွာ ရိုက္ရမယ့္ command ေတြကိုေတာ့ သိျပီးသားပါ။
ေနာက္ဆံုးအေနနဲ႔ တစ္ႀကိမ္ထပ္ေျပာပါမယ္။ Terminal မွာ သက္ဆိုင္ရာ location ကို ေရာက္ျပီးသား ျဖစ္လို႔ run မယ့္ ဖိုင္နာမည္က အဓိက က်ပါတယ္။
python ဖိုင္ျဖစ္လို႔ python နဲ႔ စပါမယ္။ ေနာက္မွာ ဖိုင္နာမည္ျဖစ္တဲ့ reader.py လိုက္ပါမယ္။
ဒါဆိုရင္ေတာ့ ခုန ဒုတိယေရးခဲ့တဲ့ read.txt ထဲက စာသားေတြ terminal ေပၚကို ေရာက္လာျပီျဖစ္ပါတယ္။
ခုလို ဖြင့္ဖတ္ႏိုင္ဖို႔အတြက္ ေရးခဲ့ရတဲ့ command line ေလးက ၂ခုတည္းျဖစ္ပါတယ္။ ေအာက္မွာ ၾကည့္ရင္ ျမင္ႏိုင္ပါတယ္။
readfile = open ('read.txt', 'r')
print readfile.read()
ဖိုင္နာမည္ေတြကို space မျခားဖုိ႔နဲ႔ မမွားဖို႔ သတိထားရပါမယ္ဗ်။
......................................................................................
...........
အေပၚမွာ ေဖာ္ျပခဲ့တဲ့  d13 ဆိုတဲ့ foder ေလးထဲမွာ reader.py နဲ႔ read.txt ဆိုတဲ့ ဖိုင္ေလး ၂ခု ပူးတြဲတည္ေဆာက္ အလုပ္လုပ္ခဲ့ၾကပါတယ္။
reader.py ဆိုတဲ့ဖိုင္ကေန read.txt ကို ဖတ္လိုက္တာပါ။
ဒီေန႔မွာေတာ့ အဲသည္လိုပဲ ေနာက္ထပ္ တစ္ခု ထပ္မံ ဖန္တီးရေအာင္ပါ။
d14 ဆိုတဲ့ နာမည္နဲ႔ folder တစ္ခု Desktop ေပၚမွာ တည္ေဆာက္ပါမယ္။
ျပီးရင္ idle >> file new ကေလး ဖြင့္ျပီး ေအာက္ပါကုဒ္လိုင္းေလးေတြ ရိုက္ထည့္လိုက္ပါ။
....
writefile = open ('write.txt', 'w')
writefile.write("I am Khit Minnyo. \n")
writefile.write("I am learning Python. \n")
writefile.write("Python is the most powerful language. \n")
writefile.write("I love Python. \n")
writefile.close()

readfile = open ('write.txt', 'r'
print readfile.read()
readfile.close()
............
အထက္ပါ လိုင္းကုဒ္ႏွစ္ခုကို လုပ္ထားခဲ့တဲ့ Desktop ေပၚက d14 folder ထဲမွာ rw.py ဆိုတဲ့ နာမည္နဲ႔ သိမ္းလိုက္ပါ။
ခုေနဖြင့္ၾကည့္ရင္ d14 ဆိုတဲ့ထဲမွာ rw.py တစ္ဖိုင္ပဲ ရွိဦးမွာပါ။ ဒါကေတာ့ ဖြင့္ၾကည့္စရာမလိုေအာင္ ရွင္းပါတယ္။
ကဲ ခုန idle ကို run ၾကည့္ၾကစို႔။ ကြ်န္ေတာ္တို႔ ျဖည့္သြင္းလိုခဲ့တဲ့ စာေတြ ေပၚလာပါမယ္။
ခုခ်ိန္မွာ d14 folder ကို ဖြင့္ၾကည့္ပါ။ rw.py အျပင္ write.txt ဆိုတဲ့ ဖိုင္ပါ ေတြ႕ရပါျပီ။
မေန႔က သင္ခန္းစာနဲ႔ အတူတြဲျပီး ေလ့လာႏိုင္ေအာင္ တစ္ေပါင္းစည္းတည္း ဖန္တီးထားေပးပါတယ္။
readfile နဲ႔ writefile
'r'      နဲ႔    'w'
ျခားနားပံုေလးကို ျမင္ေလာက္မယ္လို႔ ယူဆပါတယ္။

..................................
Lesson 12 ၾကည့္ရန္  Click Here


လာေရာက္လည္ပတ္ပတ္မႈကို အထူး ေက်းဇူးတင္ပါသည္ခင္ဗ်ာ

ဒီ Website ကေလးမွာ တင္ထားတဲ့ အေၾကာင္းအရာအေတြကို က႑အလိုက္ ေရြးခ်ယ္ ၾကည့္လိုပါက
ဒီစာေၾကာင္းေလးကို ႏွိပ္ျပီးလည္း ေရြးခ်ယ္ၾကည့္ႏိုင္သလို Menu Box ကေနလည္း ေရြးခ်ယ္ၾကည့္ႏိုင္ပါေၾကာင္း ခင္ဗ်ာ

Thanks

Khit Minnyo

No comments