🏠 Home 📚 Chapters 💻 Projects ℹ️ About
HomeProjects › Day 01
DAY 01 — 60 DAY PYTHON CHALLENGE

💻 Python Calculator

Python में Simple Calculator बनाएं — हिंदी में

Advertisement

Complete Code

python — day01.py
def calculator():
    print("=== 🧮 Python Calculator ===")
    print("1. जोड़ (+)")
    print("2. घटाव (-)")
    print("3. गुणा (*)")
    print("4. भाग (/)")

    try:
        choice = int(input("\nOperation चुनें (1-4): "))
        a = float(input("पहला number: "))
        b = float(input("दूसरा number: "))

        if choice == 1:
            print(f"\n✅ {a} + {b} = {a+b}")
        elif choice == 2:
            print(f"\n✅ {a} - {b} = {a-b}")
        elif choice == 3:
            print(f"\n✅ {a} × {b} = {a*b}")
        elif choice == 4:
            if b == 0:
                print("❌ 0 से भाग नहीं होता!")
            else:
                print(f"\n✅ {a} ÷ {b} = {a/b:.2f}")
        else:
            print("❌ गलत choice!")
    except ValueError:
        print("❌ सही number डालें!")

calculator()
OUTPUT
=== 🧮 Python Calculator === 1. जोड़ (+) 2. घटाव (-) 3. गुणा (*) 4. भाग (/) Operation चुनें (1-4): 1 पहला number: 15 दूसरा number: 5 ✅ 15.0 + 5.0 = 20.0

यह Code कैसे काम करता है?

इस calculator में functions, try-except, और if-elif-else use किया। float() से decimal numbers भी handle होते हैं। ZeroDivisionError को check करना जरूरी है।
Advertisement