Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesPython FoundationsModule 4 · Object-oriented programmingMini calculatorscenario64 / 174
+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`
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
📊 Result
Press Run to see result...

💬 Discussion

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