ဒီအခန်းပြီးရင်...
- ASCII/Unicode encoding အကြောင်းနဲ့
ord()/chr()ကို သုံးတတ်မယ် in/not inနဲ့ စာကြောင်းထဲမှာ စာသားရှာတတ်မယ်- index နဲ့ slicing သုံးပြီး စာလုံးထုတ်၊ စာကြောင်းလှန်တတ်မယ်
- string method တွေကို ဇယားကြည့်ပြီး ယုံကြည်မှုရှိရှိ သုံးတတ်မယ်
- escape character တွေကို နားလည်ပြီး သုံးတတ်မယ်
- password manager လို program အသေးတစ်ခုကို ကိုယ်တိုင်ရေးနိုင်မယ်
စာလုံးတွေရဲ့ နောက်ကွယ်က ဂဏန်းများ — Encoding
အခန်း ၂ မှာ string ဆိုတာ အက္ခရာ (character) တွေရဲ့ sequence လို့ လေ့လာခဲ့ပြီးပြီ။ ဒါပေမယ့် စိတ်ဝင်စားစရာကောင်းတဲ့ အချက်တစ်ခု ရှိတယ် — ကွန်ပျူတာက စာလုံးတွေကို တိုက်ရိုက် နားမလည်ဘူး၊ ဂဏန်းတွေပဲ နားလည်တယ် (အတွင်းထဲမှာဆို binary 0/1 တွေပေါ့)။
ဒါကြောင့် စာလုံးတစ်လုံးကို ဂဏန်းတစ်ခုအဖြစ် ပြောင်းတဲ့ စံနစ်တွေ ရှိတယ်။ စာလုံးကို ဂဏန်းပြောင်းတာကို encoding လို့ ခေါ်ပြီး၊ ဂဏန်းကနေ စာလုံးပြန်ပြောင်းတာကို decoding လို့ ခေါ်တယ်။ နာမည်ကြီး encoding စံနစ် နှစ်ခုက ASCII နဲ့ Unicode ပဲ။
Python မှာ ဒီပြောင်းလဲမှုကို လုပ်ပေးတဲ့ built-in function နှစ်ခု ရှိတယ် —
ord()— စာလုံးတစ်လုံး ပေးလိုက်ရင် သူနဲ့ သက်ဆိုင်တဲ့ ဂဏန်း (code) ကို ပြန်ပေးတယ်chr()— ဂဏန်းတစ်ခု ပေးလိုက်ရင် သူနဲ့ သက်ဆိုင်တဲ့ စာလုံးကို ပြန်ပေးတယ်
code = ord("A")
print(code) # 65
letter = chr(65)
print(letter) # A
Output:
65
A
"A" ရဲ့ ASCII code က 65 ဖြစ်တယ်။ Unicode က ASCII ထက် အများကြီး ကျယ်ပြန့်တော့ မြန်မာစာလုံးတွေလည်း code ကိုယ်စီ ရှိတယ် —
print(ord("က")) # 4096
print(chr(4096)) # က
print(ord("a")) # 97
print(chr(98)) # b
Output:
4096
က
97
b
ဒါကြောင့် ကွန်ပျူတာထဲမှာ "က" ဆိုတာ တကယ်တော့ 4096 ဆိုတဲ့ ဂဏန်းအဖြစ် သိမ်းထားတာပဲ။
မှတ်ချက်
ord() ကို စာလုံးအတိအကျ တစ်လုံးတည်း ပေးရမယ်။ ord("AB") လို့ နှစ်လုံးပေးရင် error တက်မယ်။
Reference
- Python Docs — Built-in Types — str အပါအဝင် built-in type များ
- W3Schools — Python Strings — string အခြေခံသဘောတရားများ
in နဲ့ not in — စာကြောင်းထဲမှာ ရှာခြင်း
စာကြောင်းတစ်ကြောင်းထဲမှာ ကိုယ်ရှာချင်တဲ့ စာသားပါမပါ စစ်ချင်တဲ့အခါ in operator ကို သုံးတယ်။ ပါရင် True၊ မပါရင် False ပြန်ပေးတယ် —
sentence = "I love learning Python"
if "Python" in sentence:
print("Yes, found it!")
else:
print("Not found")
Output:
Yes, found it!
ပြောင်းပြန်စစ်ချင်ရင် not in သုံးတယ်။ ဧည့်စာရင်းထဲမှာ နာမည်ပါမပါ စစ်တဲ့ နမူနာ —
guest_list = "Alice,Bob,Charlie"
name = "David"
if name not in guest_list:
print("Access denied")
else:
print("Access granted")
Output:
Access denied
"David" က guest_list ထဲမှာ မပါတော့ not in က True ဖြစ်ပြီး "Access denied" ထွက်လာတယ်။
for Loop နဲ့ စာလုံးတစ်ခုချင်း ဖြတ်သန်းခြင်း
အခန်း ၆ မှာ လေ့လာခဲ့တဲ့ for loop ကို string ပေါ်မှာ ပတ်ရင် အက္ခရာတစ်ခုချင်းစီကို ရတယ်။ ဒါကို သုံးပြီး စာကြောင်းထဲက ဂဏန်းတွေကို ဖုံးကွယ်တဲ့ program လေး ရေးကြည့်ရအောင် —
message = "Call me at 091234567"
hidden = ""
for ch in message:
if ch.isdigit():
hidden += "*"
else:
hidden += ch
print(hidden)
Output:
Call me at *********
ch.isdigit() ဆိုတာ အဲ့ဒီအက္ခရာက ဂဏန်းလားစစ်တဲ့ string method တစ်ခု (အောက်က ဇယားမှာ ထပ်တွေ့ရမယ်)။ ဖုန်းနံပါတ် ၉ လုံးကို * ၉ လုံးနဲ့ အစားထိုးလိုက်တယ်။
မှတ်ချက်
for loop တစ်ပတ်ချင်းစီမှာ ch variable ထဲကို အက္ခရာတစ်လုံးစီ ဝင်လာတယ်။ string အရှည်နဲ့ loop အကြိမ်အရေအတွက် အမြဲတူတယ်။
Reference
- W3Schools — Python Strings — string operation များ
- W3Schools — Python For Loops — string ပေါ်မှာ for ပတ်နည်း
Index နဲ့ Slicing — စာလုံးထုတ်ယူခြင်း
String ထဲက စာလုံးတစ်လုံးချင်းစီမှာ သူ့နေရာ (index) ကိုယ်စီ ရှိတယ်။ Index က 0 ကနေ စတယ် — ပထမစာလုံးက index 0၊ ဒုတိယစာလုံးက index 1... စတုရန်း ကွင်းစကွင်း [ ] နဲ့ ထုတ်ယူတယ် —
word = "Python"
print(word[0]) # ပထမစာလုံး
print(word[5]) # နောက်ဆုံးစာလုံး
print(word[-1]) # နောက်ဆုံးစာလုံး (အနုတ်နဲ့လည်း ယူလို့ရ)
print(word[-6]) # ပထမစာလုံး (အနုတ်နဲ့)
Output:
P
n
n
P
အနုတ် index က အနောက်ကနေ ရေတွက်တာ — -1 ဆိုတာ နောက်ဆုံးစာလုံး၊ -2 ဆိုတာ နောက်ဆုံးက ဒုတိယစာလုံး။
သတိပြုရန်
မရှိတဲ့ index ကို တောင်းရင် IndexError တက်မယ်။ "Python" မှာ index 0–5 ပဲ ရှိတယ်၊ word[6] လို့ တောင်းရင် program ရပ်သွားမယ်။
စာလုံးတစ်လုံးတည်း မဟုတ်ဘဲ အပိုင်းအစတစ်ခုကို ယူချင်ရင် slicing သုံးတယ် — [start:stop]။ start က ပါပြီး stop က မပါဘူး (range() လိုပဲ!) —
text = "Hello World"
print(text[0:5]) # index 0 ကနေ 4 ထိ
print(text[6:11]) # index 6 ကနေ 10 ထိ
print(text[:5]) # အစကနေ index 4 ထိ (start မထည့်ရင် 0)
print(text[6:]) # index 6 ကနေ အဆုံးထိ (stop မထည့်ရင် အဆုံး)
print(text[::2]) # တစ်လုံးခြား ယူ
print(text[::-1]) # ပြောင်းပြန်လှန်!
Output:
Hello
World
Hello
World
HloWrd
dlroW olleH
Slicing ပုံစံတွေကို ဇယားနဲ့ မှတ်ရလွယ်အောင် —
| ပုံစံ | အဓိပ္ပာယ် | ဥပမာ (text = "Hello World") |
|---|---|---|
text[i] |
index i က စာလုံးတစ်လုံး |
text[1] → 'e' |
text[start:stop] |
start ကနေ stop-1 ထိ |
text[0:5] → 'Hello' |
text[:stop] |
အစကနေ stop-1 ထိ |
text[:5] → 'Hello' |
text[start:] |
start ကနေ အဆုံးထိ |
text[6:] → 'World' |
text[::step] |
step အကွာနဲ့ ယူ |
text[::2] → 'HloWrd' |
text[::-1] |
ပြောင်းပြန်လှန် | text[::-1] → 'dlroW olleH' |
[::-1] ဆိုတာ စာကြောင်းလှန်ဖို့ အတိုဆုံး အလွယ်ဆုံး နည်းလမ်းပဲ။ လေ့ကျင့်ခန်းတွေမှာ သုံးရလိမ့်မယ်။
Reference
- W3Schools — Python Strings — indexing နဲ့ slicing ရှင်းလင်းချက်
- Python Docs — Built-in Types — sequence type များ
String Method များ
Method ဆိုတာ object တစ်ခုနဲ့ တွဲထားတဲ့ function ပဲ။ String method တွေကို my_string.method() ဆိုပြီး ခေါ်သုံးတယ်။ အသုံးအများဆုံး method တွေကို ဇယားနဲ့ စုပေးထားတယ် —
| Method | အလုပ်လုပ်ပုံ | ဥပမာ | ရလဒ် |
|---|---|---|---|
upper() |
စာလုံးအားလုံး အကြီးပြောင်း | "hello".upper() |
'HELLO' |
lower() |
စာလုံးအားလုံး အသေးပြောင်း | "Hi There".lower() |
'hi there' |
strip() |
ရှေ့နောက် space တွေ ဖယ် | " hi ".strip() |
'hi' |
lstrip() |
ဘယ်ဘက် (ရှေ့) space ဖယ် | " hi ".lstrip() |
'hi ' |
rstrip() |
ညာဘက် (နောက်) space ဖယ် | " hi ".rstrip() |
' hi' |
split() |
ခြားထားတဲ့အမှတ်နဲ့ ခွဲ → list ရ | "a,b,c".split(",") |
['a', 'b', 'c'] |
join() |
list ထဲက item တွေကို ဆက် | "-".join(["2026", "10", "05"]) |
'2026-10-05' |
find() |
စာသားရှာ → တွေ့တဲ့ index၊ မတွေ့ရင် -1 |
"hello".find("l") |
2 |
replace() |
စာသားအစားထိုး | "I like tea".replace("tea", "coffee") |
'I like coffee' |
count() |
ပါဝင်တဲ့ အကြိမ်အရေအတွက် ရေ | "banana".count("a") |
3 |
startswith() |
ဒီစာသားနဲ့ စသလား စစ် | "hello".startswith("he") |
True |
endswith() |
ဒီစာသားနဲ့ ဆုံးသလား စစ် | "hello".endswith("lo") |
True |
isdigit() |
ဂဏန်းချည်းပဲလား စစ် | "123".isdigit() |
True |
isalpha() |
အက္ခရာချည်းပဲလား စစ် | "abc".isalpha() |
True |
capitalize() |
ပထမစာလုံးကို အကြီးပြောင်း | "hello world".capitalize() |
'Hello world' |
title() |
စာလုံးတိုင်းရဲ့ ပထမအက္ခရာ အကြီးပြောင်း | "hello world".title() |
'Hello World' |
သတိပြုရန် String method တွေက မူလ string ကို မပြောင်းဘူး — အသစ်ပြောင်းထားတဲ့ string ကို ပြန်ပေးတာပဲ။ (String တွေက immutable ဖြစ်လို့။) ဒါကြောင့် ရလဒ်ကို variable ထဲ ပြန်သိမ်းရမယ်။
name = " aung aung "
name.strip() # ရလဒ်ကို မသိမ်းရင် name က မပြောင်းဘူး!
print(name) # ' aung aung ' ပဲ ထွက်နေဦးမယ်
name = name.strip() # ဒီလိုမှန်တယ်
print(name) # 'aung aung'
Method တွေကို ဆက်တိုက်ခေါ် (chain) လို့လည်း ရတယ် —
name = " aung aung "
clean = name.strip().title()
print(clean) # Aung Aung
strip() က space တွေဖယ်ပြီး 'aung aung' ပြန်ပေးတယ်၊ အဲ့ဒီရလဒ်ပေါ်မှာ title() က ထပ်အလုပ်လုပ်ပြီး 'Aung Aung' ဖြစ်သွားတယ်။ User ရိုက်ထည့်တဲ့ နာမည်တွေ သန့်ရှင်းရေးလုပ်ဖို့ ဒီပုံစံ အသုံးများတယ်။
replace() မှာ အစားထိုးမယ့် အကြိမ်အရေအတွက်ကို ကန့်သတ်လို့လည်း ရတယ် —
line = "You are my sunshine, you are my everything."
print(line.replace("are", "were")) # အားလုံးအစားထိုး
print(line.replace("are", "were", 1)) # ပထမတစ်ခုပဲ အစားထိုး
Output:
You were my sunshine, you were my everything.
You were my sunshine, you are my everything.
Reference
- W3Schools — Python String Methods — method အားလုံးရဲ့ စာရင်း
- Python Docs — Built-in Types — str method များ
Escape Character များ
တခါတလေ string ထဲမှာ ရိုးရိုးရိုက်လို့ မရတဲ့ အက္ခရာတွေ ထည့်ချင်တယ် — ဥပမာ စာကြောင်းသစ်၊ tab၊ ဒါမှမဟုတ် quote အက္ခရာကိုယ်တိုင်။ အဲ့ဒီအခါ backslash \ နဲ့ တွဲတဲ့ escape character တွေ သုံးတယ် —
| Escape | အဓိပ္ပာယ် | ဥပမာ |
|---|---|---|
\n |
စာကြောင်းသစ် (newline) | "line1\nline2" |
\t |
tab အကွာ | "name\tage" |
\\ |
backslash တစ်ခု | "C:\\temp" → C:\temp |
\' |
single quote | 'It\'s fun' → It's fun |
\" |
double quote | "Say \"hi\"" → Say "hi" |
\r |
carriage return — cursor ကို စာကြောင်းအစ ပြန်ပို့ | "12345\rAB" → AB345 |
လက်တွေ့စမ်းကြည့်ရအောင် —
print("Name:\tAung Aung\nAge:\t20")
print("Path: C:\\Users\\Aung")
print('She said, "It\'s mine!"')
Output:
Name: Aung Aung
Age: 20
Path: C:\Users\Aung
She said, "It's mine!"
\t က tab အကွာပေးတယ်၊ \n က စာကြောင်းသစ်ဆင်းတယ်။ Windows လမ်းကြောင်း (path) တွေမှာ backslash ပါတော့ \\ လို့ နှစ်ထပ်ရေးရတယ် — မဟုတ်ရင် Python က \U ကို escape character လို့ ထင်ပြီး မှားသွားမယ်။
သတိပြုရန်
\" နဲ့ \' ကို ဘယ်အချိန်သုံးလဲဆိုတော့ string ကို ပတ်ထားတဲ့ quote နဲ့ အထဲက quote တူသွားတဲ့အခါမှာပဲ။ "It's" လို့ double quote နဲ့ ပတ်ထားရင် \' မလိုဘူး — ဒါပေမယ့် 'It\'s' လို့ single quote နဲ့ ပတ်ထားရင်တော့ လိုတယ်။
Reference
- W3Schools — Python Strings — escape character များ
- Python Docs — Input/Output — string ရိုက်ထုတ်ခြင်း
str() — တခြား Type ကနေ String ပြောင်းခြင်း
ဂဏန်း ဒါမှမဟုတ် boolean ကို string နဲ့ ဆက်ချင်တဲ့အခါ (ဥပမာ message ထဲ ထည့်ချင်တာ) str() function နဲ့ ပြောင်းရတယ် —
i = 5
x = str(i)
f = 232.453543
y = str(f)
b = False
z = str(b)
print(x, type(x)) # 5 <class 'str'>
print(y) # 232.453543
print(z) # False
Output:
5 <class 'str'>
232.453543
False
သတိထားရမှာက variable နာမည်။ x = str(x) လို့ ရေးရင် x ဆိုတာ အရင်က တန်ဖိုးရှိမှ ရမယ် — မရှိရင် NameError တက်တယ်။ အထက်က နမူနာလို အရင်ဆုံး i = 5 လို့ တန်ဖိုးပေးပြီးမှ str(i) လို့ ပြောင်းတာ အမှန်ပဲ။
မှတ်ချက်
ပြောင်းပြန်လမ်းကြောင်းလည်း ရှိတယ် — int() နဲ့ float() က string ကို ဂဏန်းပြန်ပြောင်းပေးတယ်။ အခန်း ၂ မှာ လေ့လာခဲ့ပြီးပြီ။ int("42") → 42။ ဒါပေမယ့် int("hello") လို ဂဏန်းမဟုတ်တာကို ပြောင်းရင် ValueError တက်မယ်။
Reference
- Python Docs — Built-in Functions — str(), int(), float()
- W3Schools — Python User Input — input() နဲ့ type ပြောင်းခြင်း
type() နဲ့ isinstance() — Type စစ်ခြင်း
Variable တစ်ခုက ဘယ် type လဲ စစ်ချင်တဲ့အခါ နည်းလမ်း နှစ်ခု ရှိတယ် —
x = 5
if type(x) is int:
print("x is an integer")
else:
print("x is not an integer")
if isinstance(x, int):
print("x is really an integer")
Output:
x is an integer
x is really an integer
type(x) is int က တိတိကျကျ int အမျိုးအစားဟုတ်မဟုတ် စစ်တယ်။ isinstance(x, int) ကတော့ ပိုပြီး ပြေပြစ်တယ် — အမွေဆက်ခံထားတဲ့ (inheritance) type တွေကိုပါ အမှန်လို့ သတ်မှတ်ပေးတယ်။ အခု level မှာ နှစ်ခုလုံး အလုပ်တူတူပဲမို့ ကြိုက်တာသုံး၊ isinstance() က နောင်မှာ ပိုအသုံးဝင်မယ်။
Reference
- Python Docs — Built-in Functions — type() နဲ့ isinstance()
Mini Project — Simple Password Manager
အခန်းထဲမှာ သင်ခဲ့တာတွေကို စုပြီး password manager အသေးလေး ရေးကြည့်ရအောင်။ Menu နဲ့ ရွေးချယ်ခိုင်းမယ် — entry အသစ်ထည့်၊ အားလုံးပြ၊ website ရှာ၊ random password ထုတ်၊ password အားကောင်းမကောင်း စစ် —
import random
import string
entries = [] # entry တစ်ခုချင်းစီ = [website, username, password]
print("--- SIMPLE PASSWORD MANAGER ---")
while True:
print("\nMenu:")
print("1. Add New Entry")
print("2. Show All Entries")
print("3. Search by Website")
print("4. Generate Random Password")
print("5. Check Password Strength")
print("6. Exit")
choice = input("Enter your choice (1-6): ")
if choice == "1":
website = input("Website: ")
username = input("Username/Email: ")
password = input("Password (leave blank to auto-generate): ")
if password == "":
chars = string.ascii_letters + string.digits + string.punctuation
password = "".join(random.choice(chars) for _ in range(12))
print("Generated Password:", password)
entries.append([website, username, password])
print("Entry added successfully!")
elif choice == "2":
if len(entries) == 0:
print("No entries yet.")
else:
print("\n--- Saved Entries ---")
for entry in entries:
print("Website:", entry[0], "| Username:", entry[1],
"| Password:", entry[2])
elif choice == "3":
search = input("Enter website to search: ").lower()
found = False
for entry in entries:
if search in entry[0].lower():
print("Website:", entry[0], "| Username:", entry[1],
"| Password:", entry[2])
found = True
if not found:
print("No matching entry found.")
elif choice == "4":
length = input("Enter desired password length (default is 12): ")
if length.isdigit():
length = int(length)
else:
length = 12
chars = string.ascii_letters + string.digits + string.punctuation
password = "".join(random.choice(chars) for _ in range(length))
print("Generated Password:", password)
elif choice == "5":
password = input("Enter password to check: ")
has_upper = any(ch.isupper() for ch in password)
has_lower = any(ch.islower() for ch in password)
has_digit = any(ch.isdigit() for ch in password)
has_special = any(ch in string.punctuation for ch in password)
score = has_upper + has_lower + has_digit + has_special
if len(password) >= 12 and score == 4:
print("Strength: STRONG")
elif len(password) >= 8 and score >= 3:
print("Strength: MODERATE")
else:
print("Strength: WEAK")
elif choice == "6":
print("Exiting program. Goodbye!")
break
else:
print("Invalid choice. Try again.")
အဓိက အချက်တွေကို ရှင်းပြရအောင် —
- Menu loop:
while Trueနဲ့break(အခန်း ၅–၆ က nested loop အတွေး)။ - Auto-generate: password နေရာမှာ ဘာမှမရိုက်ဘဲ Enter နှိပ်ရင် အက္ခရာ+ဂဏန်း+သင်္ကေတတွေထဲက ၁၂ လုံးကို random ရွေးပေးတယ်။
string.punctuationထဲမှာ!@#$%တို့လို သင်္ကေတတွေ ပါတယ်။ - Search:
inoperator နဲ့.lower()ကို တွဲသုံးထားတယ်။ "GMAIL" လို့ ရိုက်ရှာလည်း "gmail.com" ကို တွေ့တယ် — အကြီးအသေး မခွဲခြားဘူး။ - Strength check: အမျိုးအစား ၄ မျိုး (အကြီး၊ အသေး၊ ဂဏန်း၊ သင်္ကေတ) ပါဝင်မှုကို
scoreနဲ့ ရေတွက်တယ်။ ၄ မျိုးလုံးပါပြီး အလျား ၁၂ လုံးပြည့်မှ STRONG၊ ၈ လုံးပြည့်ပြီး ၃ မျိုးပါရင် MODERATE၊ ကျန်တာ WEAK။
Sample run:
--- SIMPLE PASSWORD MANAGER ---
Menu:
1. Add New Entry
2. Show All Entries
3. Search by Website
4. Generate Random Password
5. Check Password Strength
6. Exit
Enter your choice (1-6): 5
Enter password to check: Aung@2026
Strength: MODERATE
Enter your choice (1-6): 5
Enter password to check: My$uper$ecret99
Strength: STRONG
Enter your choice (1-6): 6
Exiting program. Goodbye!
"Aung@2026" က ၉ လုံးပဲ ရှိတော့ MODERATE၊ "My$uper$ecret99" က ၁၄ လုံးနဲ့ ၄ မျိုးလုံးပါတော့ STRONG။
မှတ်ချက်
entries ဆိုတာ list ထဲမှာ list တွေ ထပ်ထည့်ထားတာပါ။ list အကြောင်းအသေးစိတ်ကို အခန်း ၈ မှာ လေ့လာရဦးမယ် — အခု "entry တစ်ခုချင်းစီကို သိမ်းထားတဲ့ စာရင်း" လို့ နားလည်ထားရင် လုံလောက်ပြီ။
Reference
- Python Docs — Built-in Types — str method များ
- W3Schools — Python Strings — string နမူနာများ
စာလုံးအမျိုးအစားအလိုက် ရေတွက်ခြင်း
Method တွေနဲ့ for loop ကို တွဲသုံးတဲ့ လက်တွေ့နမူနာတစ်ခု ကြည့်ရအောင်။ စာကြောင်းတစ်ကြောင်းထဲက အက္ခရာအကြီး၊ အက္ခရာအသေး၊ ဂဏန်း၊ ကျန်တာ (space၊ သင်္ကေတ...) တွေကို ခွဲခြားရေတွက်မယ် —
sentence = input("Enter a sentence: ")
alphabets = 0
uppercase = 0
lowercase = 0
numeric = 0
other = 0
for ch in sentence:
if ch.isupper():
uppercase += 1
alphabets += 1
elif ch.islower():
lowercase += 1
alphabets += 1
elif ch.isdigit():
numeric += 1
else:
other += 1
print("Alphabets:", alphabets)
print("Uppercase:", uppercase)
print("Lowercase:", lowercase)
print("Numeric:", numeric)
print("Other:", other)
Sample input/output:
Enter a sentence: Hi 2026!
Alphabets: 2
Uppercase: 1
Lowercase: 1
Numeric: 4
Other: 2
စစ်ကြည့်ရအောင် — "Hi 2026!" မှာ H (အကြီး)၊ i (အသေး)၊ space (other)၊ 2, 0, 2, 6 (ဂဏန်း ၄ လုံး)၊ ! (other)။ စုစုပေါင်း 2 + 4 + 2 = ၈ လုံး၊ စာကြောင်းအရှည်နဲ့ ကိုက်တယ်။ ဒီပုံစံက password စစ်တာ၊ စာသားစိစစ်တာ (validation) တွေမှာ အခြေခံအကျဆုံး နည်းလမ်းပဲ။
မှတ်ချက်
if / elif အစဉ်လိုက်စစ်တာ အရေးကြီးတယ် — အက္ခရာတစ်လုံးက အကြီး "ဒါမှမဟုတ်" အသေ "ဒါမှမဟုတ်" ဂဏန်း "ဒါမှမဟုတ်" ကျန်တာ — ၄ မျိုးထဲက တစ်မျိုးပဲ ဖြစ်နိုင်တယ်။ elif သုံးတော့ တစ်လုံးကို တစ်ခါပဲ ရေတွက်မိတယ်။
Reference
- W3Schools — Python String Methods — isupper(), islower(), isdigit()
- W3Schools — Python For Loops — for loop နမူနာများ
လေ့ကျင့်ခန်းများ
လေ့ကျင့်ခန်း ၁ (လွယ်) — သရရေတွက်ခြင်း။ User ရိုက်ထည့်တဲ့ စာကြောင်းထဲမှာ သရ (a, e, i, o, u — အကြီးအသေး နှစ်မျိုးလုံး) ဘယ်နှစ်လုံး ပါလဲ ရေတွက်ပြပါ။
Sample input/output:
Enter a sentence: Hello World
Vowels: 3
လေ့ကျင့်ခန်း ၂ (အလယ်) — Slicing မသုံးဘဲ စာကြောင်းလှန်ခြင်း။
[::-1] ဒါမှမဟုတ် တခြား reverse method မသုံးဘဲ၊ for loop နဲ့ စာကြောင်းကို ပြောင်းပြန်လှန်ပြပါ။
Sample input/output:
Enter a string: Hello World!
Reversed: !dlroW olleH
လေ့ကျင့်ခန်း ၃ (အလယ်) — Palindrome စစ်ဆေးခြင်း။
စာလုံးတစ်လုံး ရိုက်ထည့်ရင် အဲ့ဒါက palindrome (အရှေ့ကနေဖတ်ဖတ် အနောက်ကနေဖတ်ဖတ် အတူတူ) ဟုတ်မဟုတ် စစ်ပြပါ။ အကြီးအသေး မခွဲခြားပါနဲ့ (lower() သုံးပါ)။
Sample input/output:
Enter a word: Madam
"Madam" is a palindrome.
Enter a word: hello
"hello" is not a palindrome.
လေ့ကျင့်ခန်း ၄ (ခက်) — # ကြားက အရှည်ဆုံး စာသား။
# သင်္ကေတတွေပါတဲ့ စာကြောင်းတစ်ကြောင်း ရိုက်ထည့်ရင် # နှစ်ခုကြားက အရှည်ဆုံး စာသားရဲ့ အလျားကို ရိုက်ထုတ်ပါ။ # တစ်လုံးတည်း (ဒါမှမဟုတ်) # လုံးဝမပါရင် No largest substring!!! လို့ ရိုက်ထုတ်ပါ။
Sample input/output:
Enter a string: py#cat#elephant#ox#
Longest length: 8
Enter a string: hello#world
No largest substring!!!
လေ့ကျင့်ခန်း ၅ (အလယ်-ခက်) — Username စစ်ဆေးခြင်း။ Username တစ်ခု ရိုက်ထည့်ရင် စည်းကမ်းနဲ့ ကိုက်ညီမညီ စစ်ပါ —
- အလျား ၄ လုံးကနေ ၁၂ လုံးကြား
- အက္ခရာ၊ ဂဏန်း၊ underscore (
_) ပဲ ပါရမယ်
Sample input/output:
Enter username: aung_2026
Valid username.
Enter username: ab
Invalid username.
Enter username: aung aung
Invalid username.