Files
Clawd Bot ca9b510922 chore: align with upstream openclaw/openclaw and overlay local additions
- Reset master to upstream/main (16,697 commits)
- Overlay 2,271 local-only files (skills, tools, workspace, configs, apps)
- Restore IDENTITY.md and USER.md templates
- Build verified, gateway running, Discord working

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 07:40:46 +01:00

83 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
Simple Calculator
Supports basic arithmetic operations: +, -, *, /, **, %
"""
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Error: Division by zero"
return x / y
def power(x, y):
return x ** y
def modulo(x, y):
if y == 0:
return "Error: Modulo by zero"
return x % y
def calculator():
print("=" * 40)
print(" Simple Calculator")
print("=" * 40)
print("\nOperations:")
print(" + : Addition")
print(" - : Subtraction")
print(" * : Multiplication")
print(" / : Division")
print(" ** : Power")
print(" % : Modulo")
print(" q : Quit")
print("=" * 40)
while True:
try:
operation = input("\nEnter operation (or 'q' to quit): ").strip()
if operation.lower() == 'q':
print("Thanks for using the calculator!")
break
if operation not in ['+', '-', '*', '/', '**', '%']:
print("Invalid operation. Please try again.")
continue
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if operation == '+':
result = add(num1, num2)
elif operation == '-':
result = subtract(num1, num2)
elif operation == '*':
result = multiply(num1, num2)
elif operation == '/':
result = divide(num1, num2)
elif operation == '**':
result = power(num1, num2)
elif operation == '%':
result = modulo(num1, num2)
print(f"\nResult: {num1} {operation} {num2} = {result}")
except ValueError:
print("Invalid input. Please enter valid numbers.")
except KeyboardInterrupt:
print("\n\nCalculator interrupted. Goodbye!")
break
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
calculator()