Skip to main content
← CoursesPython FoundationsModule 4 · Object-oriented programmingMini calculatorscenario61 / 170
💬 Discuss🧪 Playground+125 XP
Task
📝 **Task:** Mini-calculator `calc(a, op, b)`. Support `+`, `-`, `*`, `/`. Division by 0 → `"Error"`. 📋 **Steps:** 1. `def calc(a, op, b):` 2. Check `op` via `if`: - `"+"` → `return a + b` - `"-"` → `return a - b` - `"*"` → `return a * b` - `"/"` → if `b == 0` return `"Error"`, else `a / b` 💡 **Similar example:** ```python def simple_op(a, op, b): if op == "+": return a + b if op == "-": return a - b return "Unknown" ``` 🎯 **Expected output:** `15\nError`

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only — ~5-10s. Stays cached afterward.
📊 Result
Press Run to see result...
📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…