Thuta Learning
ရှာဖွေရန်
ProjectsProgrammingbeginner

Calculator App (Enhanced)

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

🐍 Lesson 42: Calculator App (Python Project)

1. Project Overview

မြန်မာ → Calculator App ဆိုတာ Python beginner တွေအတွက် အလွယ်ဆုံး project တစ်ခုဖြစ်ပြီး addition, subtraction, multiplication, division လို အခြေခံ arithmetic operations တွေကို လုပ်ပေးနိုင်မယ်။

English → A calculator app is a beginner-friendly project that performs basic arithmetic operations like addition, subtraction, multiplication, and division.

2. Why Build a Calculator App?

  • Python functions, loops, conditionals ကို practice လုပ်နိုင်မယ်
  • User input ကို handle နည်း သင်ယူနိုင်မယ်
  • Error handling (ဥပမာ – division by zero) ကို စမ်းသပ်နိုင်မယ်

3. အကျဉ်းချုပ်

✅ Calculator app = beginner-friendly project

✅ CLI version → functions, loops, conditionals practice

✅ GUI version → Tkinter သုံးပြီး interactive app

✅ Error handling → division by zero, invalid input

python
# ===== 1. Basic Calculator Functions =====
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:
        return "Error! Division by zero."
    return a / b

# ===== 2. Calculator Loop =====
print("===== Simple Calculator =====")
print("Operations: +, -, *, /")
print("Enter 'q' to quit\n")

while True:
    choice = input("Enter operation (+, -, *, /) or 'q' to quit: ")
    if choice == 'q':
        break
    
    try:
        num1 = float(input("Enter first number: "))
        num2 = float(input("Enter second number: "))
        
        if choice == '+':
            print(f"Result: {add(num1, num2)}\n")
        elif choice == '-':
            print(f"Result: {subtract(num1, num2)}\n")
        elif choice == '*':
            print(f"Result: {multiply(num1, num2)}\n")
        elif choice == '/':
            result = divide(num1, num2)
            print(f"Result: {result}\n")
        else:
            print("Invalid operation\n")
    except ValueError:
        print("Invalid input! Please enter numbers.\n")

# ===== 3. Example Usage =====
print(f"\n===== Example Calculations =====")
print(f"5 + 3 = {add(5, 3)}")
print(f"10 - 4 = {subtract(10, 4)}")
print(f"6 * 7 = {multiply(6, 7)}")
print(f"15 / 3 = {divide(15, 3)}")
print(f"10 / 0 = {divide(10, 0)}")
You should see
===== Simple Calculator ===== Operations: +, -, *, / Enter 'q' to quit ===== Example Calculations ===== 5 + 3 = 8 10 - 4 = 6 6 * 7 = 42 15 / 3 = 5.0 10 / 0 = Error! Division by zero.
Calculator App (Enhanced) | Thuta Learning