Class Share Social Forums
Please create an account or login to connect with your friends.


Class Share Social Forums
Please create an account or login to connect with your friends.

Class Share Social Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Class Share Social ForumsLog in

Connect with your classmates


descriptionHow to see clearly EmptyHow to see clearly

more_horiz
မနေ့က input function သုံးပြီး program လေးတစ်ခုလုပ်ခဲ့တယ်နော်။ Laughing Cool
ပျော်ဖို့ကောင်းတယ်ဟုတ်။
အိုခေ။ ဒီတစ်ခါ ကွန်ပျူတာက ကျနော်တို့ နာမည်ကိုမေးပြီး မိတ်ဆက်တဲ့ program လေးဆွဲကြည့်ရအောင်။ ဒီစာကိုဆက်မဖတ်ဘဲ ကြိုးစားကြည့်ပါဦး။ hint ပေးရမယ်ဆိုရင် string နှစ်ခုဟာ ပေါင်းလို့ရပါတယ်။ example, "Hello " + " Maung Maung "

Go ahead and try this.....

Okay....
လုပ်နိုင်မယ်လို့ထင်ပါတယ်။
အဖြေက
name = input(" What's your name? ")
print( 'Hi' + name )

လွယ်ပါတယ်နော်။
တစ်ခုချင်းဆီကြည့်မယ်ဆိုရင် ကျနော်တို့ user ရဲ့ နာမည်ကို တောင်းပြီး name လို့ variable တစ်ခုသတ်မှတ်လိုက်တယ်။
ပြီးတော့ " Hi " ဆိုတဲ့ string စကားလုံးနဲ့ name ကို ပေါင်းပြီး ဖော်ပြလိုက်တယ်။
မှတ်ထားရမှာက string အချင်းချင်းပေါင်းလို့ရပါတယ်။ maths operations တွေထဲမှာမှ ပေါင်းတာတစ်ခုပဲရပါတယ်။

နောက်တစ်ခုဆက်သွားကြမယ်။
မနေ့က ရှာခိုင်းတဲ့ formatted string နဲ့ပတ်သက်ပြီး သိထားတာလေးတွေရှိရင် comment ပေးထားပါဦး။

ဆိုပါတော့။ ကျနော်တို့က အစောကလို နာမည်တွေကို ဖော်ပြချင်တယ်ပေါ့။ အဲ့ဒီအခါ user ရဲ့နာမည်ကို string တွေနဲ့ပေါင်းပြီးဖော်ပြလို့ရပါတယ်။
ဒါပေမယ့် နာမည်တွေ ၊ ဖော်ပြရမယ့်စာတွေ များလာရင်ရော။
ဥပမာ - Hello, Your name is Maung Maung and you are 20 years old လို့ဖော်ပြချင်ရင်
အစောကလို print ( " Hello , Your name is " + name + "and you are " + age + "years old.". ) လို့ ရိုက်ရပါလိမ့်မယ်။

မျက်စိရှုပ်တာရယ် ၊ quotation တွေများတာရယ်ကြောင့် မှားနိုင်ပါတယ်။ ဒါကြောင့် ရှင်းပြီး လွယ်ကူဖို့အတွက် formatted string ဆိုပြီးရှိပါတယ်။
သုံးရတာလွယ်ပါတယ်။
အစောက ဥပမာလေး ပြန်လုပ်ကြည့်မယ်။

name = input(" What is your name? ")
age = int(input(" How old are you? ")
print ( f' Hello, Your name is {name} and you are {age} years old')

ရှင်းသွားတယ်ဟုတ်။
တွန့်ကွင်း {} ထဲက name နဲ့ ‌age တွေက variable တွေဖြစ်ပါတယ်။
Formatted string ကိုအသုံးပြုဖို့ဆိုရင် f' xxxxxx ' လို့ရေးပေးရပါတယ်။ quotation သုံးတာကို သတိပြုပေးပါနော်။

ဒီတစ်ခါ program နောက်တစ်ခုထပ်ဆွဲစေချင်ပါတယ်။
မနေ့က ကမ္ဘာပေါ်မှာ ဘယ်နရက်နေပြီးပြီလဲ ဆိုတဲ့ program လေးကို run လိုက်ရင် အဖြေက You have lived on Earth for xxxx days . လို့ ပြအောင် လုပ်ကြည့်စေချင်ပါတယ်။

နောက်တစ်ခုဆက်သွားမယ်နော်။
python မှာ print ၊ input တို့လိုမျိုး function တွေ အများကြီးရှိပါတယ်။ ကားမောင်းတာနဲ့ယှဉ်ပြရရင် ကားကို ရပ်မယ် ၊ မောင်းမယ်ဆိုတာ လုပ်ဆောင်ချက် function ဖြစ်ပါတယ်။ method ဆိုတာကတော့ သူ့အဓိပ္ပာယ်အတိုင်း ကားကို ဘယ်နှုန်းနဲ့မောင်းမယ် ၊ မြန်မယ် ၊ ဘာညာပေါ့။ method က object အပေါ်မူတည်ပါတယ်။ ဆိုလိုတာက နှေးတယ် ၊ မြန်တယ်ဆိုတာ ကားရှိမှ လုပ်လို့ရတာမိုလို့ပါ။
python မှာ method တွေများစွာရှိပါတယ်။
method တွေထဲက အချို့ကို မိတ်ဆက်ပေးချင်ပါတယ်။
ရှေ့က ဥပမာတွေမှာ ကျနော်တို့က print ကိုသူံးရင် screen ပေါ်မှာ တစ်ခုခုဖော်ပြမယ်လို့ ဆိုလိုပါတယ်။ ဒါကိုဖော်ပြတဲ့အခါ စာလုံးအကုန်အကြီးလား၊ အသေးနဲ့လားပေါ့။ ဒါက method လို့ခေါ်ပါတယ်။
စာလုံးအကြီးတွေဖော်ပြချင်တဲ့အခါ
upper() method ကိုအသုံးပြုပါတယ်။
name = " Maung Maung ".upper()
print(name)

.upper() ဆိုတာ string ကို အကြီးစာလုံးတွေအဖြစ်ပြောင်းမယ်လို့ဆိုလိုပါတယ်။
သတိထားရမှာက name.upper() = "Maung Maung " လို့ရေးလို့မရပါဘူး။
အသေးစလုံးပြောင်းချင်တယ်ဆိုရင်တော့ name = " Maung Maung ".lower() ပေါ့။
print (name) လို့ရိုက်ကြည့်ပါ။

နောက်တစ်ခုက စာလုံးတွေရဲ့တည်နေရာကို ရှာတဲ့ find method ပါ။
name = "Maung Maung "
print(name.find('a'))
သူက ပထမဆုံးတွေ့တဲ့ a ကိုပဲဖော်ပြပါလိမ့်မယ် ။ ဖော်ပြတဲ့အခါ နံပါတ်တွေနဲ့ပြပါလိမ့်မယ်။
M ကနေစပြီး ၀ ကနေစပါတယ်။ 1 လို့စမယူပါဘူးနော်။
ဒါကြောင့် ‌a ဟာ နံပါတ် ၁ မှာရှိပါတယ်။

Okey....
ကျန်တဲ့ replace , count ...method တွေကို ဘယ်လိုသုံးရလဲဆိုတာ ရှာပြီးစမ်းကြည့်ပါဦး။

ဒီနေ့အတွက် လေ့ကျင့်ဖို့က

User ရဲ့ First name နဲ့ last name ကိုတောင်းမယ်။ပြီးရင် အကြိုက်ဆုံးအရောင်ကို တောင်းမယ် ။ နောက်ဆုံးမှာ You are .....and you love ..... လို့ ဖော်ပြပေးမယ့် program လေးဆွဲစေချင်ပါတယ်။

Bye for now..... Smile

မနက်ဖန်အတွက် ရှာရမယ့်ဟာက နည်းပါတယ်။
How to use if and else in Python? ပါ။
ဒီတစ်ခုပဲရှာခဲ့ပါ။
မနက်ဖန်မှာ calculator လေးတစ်ခု ဖန်တီးမယ်နော်။ I love you bounce

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
သိသမျှကို စာအုပ်ထဲရေးမှတ်ထားဖို့မမေ့ပါနဲ့နော် အကို အစ်မတို့။

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
String formattingဆိုတာက variableတွေကို ကိုယ်လိုချင်တဲ့အစီအစဉ်တိုင်းနေရာချတာ (meaningကိုသေချာမတွေ့လို့ ထင်ရာပြောတာ😁)
Formatလုပ်နည်းတွေက 4မျိုးလောက်
တွေ့တယ် %, %s, %d, str.format, f-string
မောင်လေးသင်ပေးတဲ့ f-stringက အလွယ်ဆုံးထင်တယ် တခြားဟာတွေက ရှုပ်တယ်ကြာတယ် f-stringက updateဖြစ်တယ် Python 3.6+မှာပဲ သုံးလို့ရတယ်

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
Formatted string မှာ ယေဘုယျနှစ်မျိုးတွေတယ်၊ Traditional နဲ့ C-styleတဲ့၊ အဲ့ထဲက ၄ မျိုးထပ်တွေ့ပါတယ်၊ %s,%d,%. တို့အဲ့တာတွေက မှတ်ရများပြီး ရှုပ်တော့ ခက်ပါတယ်၊ f-string ကတော့ အဆင်အပြေဆုံးပဲ၊ အခုတော့ လေ့ကျင့်နေတုန်းပါ

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
ကျနော်တို့ အတွက် f string သုံးတတ်ရင်ကို program တွေဆွဲရင် အဆင်ပြေပါတယ် အကိုတို့ အစ်မတို့

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
Methodက format, format_mapက formatted stringနဲ့တူလား methodအကုန်လုံးသိဖို့လိုလား အဲ့ဒါလုပ်နေတာ မပြီးလို့့ရှေ့မတက်နိုင်ဘူး ဖြစ်နေတယ်😅

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
Method ကတော့ ကိုယ်အသုံးပြုတဲ့ string၊ သို့မဟုတ် user ကနေ ဖြည့်ရမယ့် string ကို ပုံစံချပေးခြင်းတစ်မျိုးပါပဲ၊ တစ်ခုမေးချင်တာက အပေါ်က အစ်မ အောက်ဆုံးအကြောင်းမှာ မေးသလိုပါပဲ😁

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
Method ကအကုန်လူံးသိဖို့ မလိုပါဘူး မမဆုနဲ့ အကိုနေလင်းကျော်ရေ။ programmer တွေတောင် မသိတဲ့သူတွေရှိပါတယ်ဗျ။ ဒါကြောင့် ကျနော်က မိတ်ဆက်သဘောအနေနဲ့ပဲ ထည့်ပေးတာပါ။💚😉

descriptionHow to see clearly EmptyRe: How to see clearly

more_horiz
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply