Quick Dash Calculator |link| Today

# Safe arithmetic using Python's eval (restricted) # In production, use a restricted environment or ast.literal_eval with operators. allowed_names = k: v for k, v in math.__dict__.items() if not k.startswith("__") allowed_names.update("abs": abs, "round": round) try: return eval(expr, {"__builtins__": {}}, allowed_names) except Exception: return "Error: invalid expression" if name == " main ": test_cases = [ "12*3.5+2", "15% of 200", "avg(4,8,12)", "tip(45.80,15)", "split(120,4)" ] for case in test_cases: print(f"case → evaluate(case)")

import math def evaluate(expr: str) -> float | str: """ Quick Dash Calculator evaluator. Supports arithmetic, %, avg/sum, tip/split. """ expr = expr.strip().lower() quick dash calculator

# Built-in dash functions if expr.startswith('sum'): nums = [float(x) for x in expr[3:].strip('()').split(',')] return sum(nums) if expr.startswith('avg'): nums = [float(x) for x in expr[3:].strip('()').split(',')] return sum(nums) / len(nums) if nums else 0 if expr.startswith('tip'): # tip(total, percentage) args = expr[3:].strip('()').split(',') total, pct = float(args[0]), float(args[1]) return round(total * pct / 100, 2) if expr.startswith('split'): args = expr[5:].strip('()').split(',') total, people = float(args[0]), int(args[1]) return round(total / people, 2) # Safe arithmetic using Python's eval (restricted) #

| Operation | Time (ms) | |-----------|-----------| | 45 + 78 * 2 | 0.21 | | avg(1,2,3,4,5,6,7,8,9,10) | 0.35 | | 15% of 499.99 | 0.28 | | tip(250,20) | 0.22 | | (2^10 + 5) / 3 | 0.31 | """ expr = expr

if expr.endswith('%'): # relative to last result (simplified: returns % as decimal) return float(expr[:-1]) / 100

{"529463":"https:\/\/experiencestores.oneplus.in\/oneplus-exclusive-service-center-oneplus-esc-pune-seasons-mall-mobile-phone-repair-shop-hadapsar-pune-126841\/TimelineDetails\/529463","527622":"https:\/\/experiencestores.oneplus.in\/oneplus-exclusive-service-center-oneplus-esc-pune-seasons-mall-mobile-phone-repair-shop-hadapsar-pune-126841\/TimelineDetails\/527622","527621":"https:\/\/experiencestores.oneplus.in\/oneplus-exclusive-service-center-oneplus-esc-pune-seasons-mall-mobile-phone-repair-shop-hadapsar-pune-126841\/TimelineDetails\/527621"}