python
advanced
हल किया
2026-11-24 को समाप्त
Calculator: evaluate an expression
Write evaluate(expr) that computes an arithmetic expression given as text, without eval, exec or ast.literal_eval.
- Numbers can be integers or decimals (
3,2.5). - Operators
+ - * /with normal precedence, and parentheses. - Unary minus:
-3,2 * -(1 + 1). - Spaces may appear anywhere.
- Raise
ValueErrorfor invalid input ("2 +","(1","4 $ 2") andZeroDivisionErrorfor division by zero.
Acceptance criteria
- Return a
float. - The tests at the bottom print
All tests passed.
Hint: a tokenizer plus a recursive-descent parser (expression → term → factor) keeps this short.
अब तक 0 लोगों ने हल किया।
एडिटरCtrl + Enter
जब टेस्ट "All tests passed" दिखाते हैं, तो चैलेंज इस ब्राउज़र में हल के रूप में चिह्नित हो जाता है।
अपना समाधान समीक्षा के लिए भेजें