give me the most lightweight code, for a CLI calculator
- User
give me the most lightweight code, for a CLI calculator
Assistant
Here's an ultra-lightweight CLI calculator in Python using just 3 lines of code:
pythonwhile True: try: print(eval(input("> "))) except: breakFeatures:
- Uses only built-in functions
- Supports all basic operations (+, -, *, /, **, etc)
- Handles exit on any invalid input
- No dependencies
- Works on any Python installation
Example usage:
code> 2+3*4 14 > 10/2 5.0 > 2**8 256The calculator will exit automatically if you:
- Enter invalid syntax
- Press Ctrl+C
- Enter something like 'exit()' or any non-math input
For a version that keeps running until you type 'exit':
python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.