Projects — လက်တွေ့ Project များ
Module 8 ရဲ့ Number Guessing Game ကနေ တစ်ဆင့်မြင့်ပြီး Project ၃ ခုကို တည်ဆောက်ကြပါမယ်။ Project တစ်ခုချင်းစီမှာ ကျွန်တော်တို့ သင်ခဲ့ရတဲ့ Concepts တွေ အားလုံး ပါဝင်နေပါတယ်။
Project 1 — To-do List CLI App
Section titled “Project 1 — To-do List CLI App”အသုံးပြုမယ့် Concepts များ
Section titled “အသုံးပြုမယ့် Concepts များ”- Lists, Dictionaries, File Handling, Functions, Loops, Error Handling
ဘာကို Build လုပ်မလဲ?
Section titled “ဘာကို Build လုပ်မလဲ?”Terminal မှာ အလုပ်လုပ်မယ့် To-do List ဖြစ်ပါတယ် — Tasks တွေ အသစ်ထည့်လို့ ရမယ်၊ ပြီးစီးကြောင်း မှတ်လို့ ရမယ်၊ ဖျက်လို့ ရမယ် — ပြီးတော့ File ထဲမှာ Save ထားမှာဖြစ်လို့ Program ပိတ်ပြီး ပြန်ဖွင့်ရင်တောင် Tasks တွေ မပျောက်ပျက်သွားပါဘူး။
import jsonimport os
TODO_FILE = "todos.json"
def load_todos(): """ဖိုင်ကနေ Tasks တွေ ဖတ်ခြင်း""" if not os.path.exists(TODO_FILE): return [] with open(TODO_FILE, "r", encoding="utf-8") as f: return json.load(f)
def save_todos(todos): """Tasks တွေကို ဖိုင်ထဲ သိမ်းဆည်းခြင်း""" with open(TODO_FILE, "w", encoding="utf-8") as f: json.dump(todos, f, ensure_ascii=False, indent=2)
def show_todos(todos): """Tasks တွေ ပြသခြင်း""" if not todos: print("📭 Tasks တွေ မရှိသေးပါ။") return print("\n=== To-do List ===") for i, task in enumerate(todos, start=1): status = "✅" if task["done"] else "⬜" print(f"{i}. {status} {task['title']}") print()
def add_todo(todos, title): """Task အသစ် ထည့်ခြင်း""" todos.append({"title": title, "done": False}) save_todos(todos) print(f"✅ Task အသစ် ထည့်သွင်းပြီးပါပြီ: {title}")
def complete_todo(todos, number): """Task ပြီးစီးကြောင်း မှတ်ခြင်း""" if 1 <= number <= len(todos): todos[number - 1]["done"] = True save_todos(todos) print(f"🎉 Task {number} ပြီးစီးပါပြီ!") else: print("❌ မှားယွင်းသော Task နံပါတ်ပါ")
def delete_todo(todos, number): """Task ဖျက်ခြင်း""" if 1 <= number <= len(todos): removed = todos.pop(number - 1) save_todos(todos) print(f"🗑️ Task ဖျက်ပြီးပါပြီ: {removed['title']}") else: print("❌ မှားယွင်းသော Task နံပါတ်ပါ")
def main(): todos = load_todos()
print("🗒️ Python To-do List မှ ကြိုဆိုပါတယ်!")
while True: print("\n[1] Tasks တွေကို ကြည့်မယ်") print("[2] Task အသစ် ထည့်မယ်") print("[3] Task ပြီးကြောင်း မှတ်မယ်") print("[4] Task ကို ဖျက်မယ်") print("[5] ထွက်မယ်")
choice = input("\nရွေးချယ်ပါ (1-5): ").strip()
if choice == "1": show_todos(todos)
elif choice == "2": title = input("Task နာမည်: ").strip() if title: add_todo(todos, title) else: print("❌ Task နာမည် ထည့်ပေးပါ")
elif choice == "3": show_todos(todos) try: num = int(input("ပြီးကြောင်း မှတ်မယ့် Task နံပါတ်ကို ထည့်ပါ: ")) complete_todo(todos, num) except ValueError: print("❌ ကျေးဇူးပြု၍ ဂဏန်းသာ ရိုက်ထည့်ပါ")
elif choice == "4": show_todos(todos) try: num = int(input("ဖျက်မယ့် Task နံပါတ်ကို ထည့်ပါ: ")) delete_todo(todos, num) except ValueError: print("❌ ကျေးဇူးပြု၍ ဂဏန်းသာ ရိုက်ထည့်ပါ")
elif choice == "5": print("👋 ထွက်သွားပါပြီ! နောက်မှ ပြန်ဆုံကြမယ်နော်") break
else: print("❌ 1 မှ 5 ကြားသော ဂဏန်းကိုသာ ရွေးချယ်ပါ")
main()Code ကို ပြန်လည် လေ့လာခြင်း
Section titled “Code ကို ပြန်လည် လေ့လာခြင်း”| Code | သင်ယူခဲ့ရတဲ့ Concept |
|---|---|
load_todos() / save_todos() | File Handling (Module 6) |
json.load() / json.dump() | JSON + Modules (Module 6, 7) |
enumerate(todos, start=1) | Comprehensions & Built-ins (Module 4.5) |
todos.append(), todos.pop() | Lists (Module 4) |
try / except ValueError | Error Handling (Module 6) |
while True + break | Loops (Module 2) |
Project 2 — Simple Calculator
Section titled “Project 2 — Simple Calculator”အသုံးပြုမယ့် Concepts များ
Section titled “အသုံးပြုမယ့် Concepts များ”- Functions, Error Handling, Control Flow, While Loop
def add(a, b): return a + b
def subtract(a, b): return a - b
def multiply(a, b): return a * b
def divide(a, b): if b == 0: raise ValueError("သုညနဲ့ စားလို့ မရပါဘူး!") return a / b
def get_number(prompt): """User ဆီကနေ ကိန်းဂဏန်း တောင်းခံခြင်း""" while True: try: return float(input(prompt)) except ValueError: print("❌ ကျေးဇူးပြု၍ ကိန်းဂဏန်းသာ ရိုက်ထည့်ပါ")
def calculator(): print("🔢 Python Calculator") print("===================")
operations = { "1": ("ပေါင်းခြင်း (+)", add), "2": ("နှုတ်ခြင်း (-)", subtract), "3": ("မြှောက်ခြင်း (×)", multiply), "4": ("စားခြင်း (÷)", divide), }
while True: print("\nလုပ်ဆောင်ချက်ကို ရွေးချယ်ပါ:") for key, (label, _) in operations.items(): print(f" [{key}] {label}") print(" [5] ထွက်မယ်")
choice = input("\nရွေးချယ်ပါ: ").strip()
if choice == "5": print("👋 ထွက်သွားပါပြီ!") break
if choice not in operations: print("❌ 1 ကနေ 5 ကြားကိုသာ ရွေးချယ်ပါ") continue
label, operation = operations[choice]
a = get_number("ပထမ ကိန်းဂဏန်းကို ထည့်ပါ: ") b = get_number("ဒုတိယ ကိန်းဂဏန်းကို ထည့်ပါ: ")
try: result = operation(a, b) print(f"\n✅ {a} {label[-2]} {b} = {result}") except ValueError as e: print(f"❌ {e}")
calculator()Project 3 — Word Frequency Counter
Section titled “Project 3 — Word Frequency Counter”အသုံးပြုမယ့် Concepts များ
Section titled “အသုံးပြုမယ့် Concepts များ”- File Handling, Dictionaries, Sorting, String Methods, Comprehensions
import os
def count_words(text): """စာသားထဲမှာ Word တစ်ခုချင်းစီ ဘယ်နှစ်ကြိမ် ပါသလဲဆိုတာ ရေတွက်ခြင်း""" # Lowercase ပြောင်းမယ် + Punctuation တွေကို ဖယ်ရှားမယ် cleaned = text.lower() for char in ".,!?;:\"'()[]{}": cleaned = cleaned.replace(char, "") words = cleaned.split()
# Dictionary အသုံးပြုပြီး ရေတွက်ခြင်း freq = {} for word in words: freq[word] = freq.get(word, 0) + 1 # .get() — Module 4 မှ Dictionary Safe Access
return freq
def show_top_words(freq, top_n=10): """အများဆုံး ပါဝင်တဲ့ Words တွေကို ပြသခြင်း""" sorted_words = sorted(freq.items(), key=lambda x: x[1], reverse=True)
print(f"\n=== အများဆုံး ပါဝင်သော Words (Top {top_n}) ===") for rank, (word, count) in enumerate(sorted_words[:top_n], start=1): bar = "█" * min(count, 30) # Visual bar ပြသဖို့ print(f"{rank:2}. {word:<15} {count:3} ကြိမ် {bar}")
def main(): print("📊 Word Frequency Counter") print("==========================") print("[1] Text ကို တိုက်ရိုက် ရိုက်ထည့်ပါမယ်") print("[2] ဖိုင်ထဲကနေ ဖတ်ပါမယ်")
choice = input("\nရွေးချယ်ပါ (1/2): ").strip()
if choice == "1": print("Text ထည့်ပါ (ပြီးရင် Enter ကို 2 ခါ နှိပ်ပါ):") lines = [] while True: line = input() if line == "": break lines.append(line) text = " ".join(lines)
elif choice == "2": filename = input("ဖိုင်နာမည် ထည့်ပါ (.txt): ").strip() if not os.path.exists(filename): print(f"❌ '{filename}' ဖိုင် မတွေ့ပါဘူး") return with open(filename, "r", encoding="utf-8") as f: text = f.read()
else: print("❌ 1 သို့မဟုတ် 2 ကိုသာ ရွေးချယ်ပါ") return
if not text.strip(): print("❌ Text မရှိပါဘူး") return
freq = count_words(text)
print(f"\n📈 စုစုပေါင်း Unique Words အရေအတွက်: {len(freq)}") print(f"📝 စုစုပေါင်း Words အရေအတွက်: {sum(freq.values())}")
show_top_words(freq, top_n=10)
main()နောက်ဆင့် Challenge များ
Section titled “နောက်ဆင့် Challenge များ”ဒီ Projects တွေကို ပိုမိုကောင်းမွန်အောင် ဆက်လက် ကြိုးစားကြည့်ပါ:
To-do List:
- Due Date ထည့်ပါ (datetime module ကို သုံးကြည့်ပါ)
- Priority Level တွေ ထည့်ပါ (High / Medium / Low)
- Search Function အသစ် ထည့်ပါ
Calculator:
- တွက်ခဲ့တဲ့ History ကို သိမ်းဆည်းပါ
- Square root, Power စတဲ့ လုပ်ဆောင်ချက်တွေ ထပ်ထည့်ပါ
- Memory function တွေ (M+, M-, MR) ထည့်သွင်းပါ
Word Counter:
- Top Common Words တွေ (the, a, is စသဖြင့်) ကို ဖြုတ်ပြပါ (Stopwords)
- Word Cloud ပုံစံမျိုး ဆောက်ကြည့်ပါ
- Result တွေကို CSV ဖိုင်ထဲ Export ထုတ်ကြည့်ပါ
Python Course တစ်ခုလုံး အောင်မြင်စွာ ပြီးဆုံးပါပြီ — ဂုဏ်ယူပါတယ်! 🎉