math-calculator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Math Calculator Skill

数学计算器Skill

Overview

概述

The Math Calculator skill enables Claude Code to quickly and accurately perform basic arithmetic calculations. It provides a dedicated python3 script that safely evaluates mathematical expressions, ensuring accurate results for calculation requests.
数学计算器Skill可以让Claude Code快速准确地执行基础算术计算。它提供了专用的python3脚本,能够安全地计算数学表达式,确保计算请求的结果准确。

When to Use This Skill

何时使用该Skill

Use this skill when:
  • Claude Code receives a math question (e.g., "What is 5 * 5?")
  • A user asks to calculate an arithmetic expression (e.g., "Calculate 100 / 4 + 2")
  • Quick, reliable calculations are needed to support a larger task
  • Exact numerical results are important for subsequent operations
在以下场景使用该Skill:
  • Claude Code收到数学问题(例如:"What is 5 * 5?")
  • 用户要求计算某个算术表达式(例如:"Calculate 100 / 4 + 2")
  • 需要快速可靠的计算来支撑更大的任务
  • 精确的数值结果对后续操作很重要

Quick Start

快速开始

Execute the calculation script with the mathematical expression:
bash
python3 scripts/calculate.py "5 * 5"
python3 scripts/calculate.py "100 / 4 + 2"
python3 scripts/calculate.py "sqrt(25) + 10"
传入数学表达式执行计算脚本:
bash
python3 scripts/calculate.py "5 * 5"
python3 scripts/calculate.py "100 / 4 + 2"
python3 scripts/calculate.py "sqrt(25) + 10"

Supported Operations

支持的运算

The calculator supports basic arithmetic and common functions:
  • Addition:
    5 + 3
    = 8
  • Subtraction:
    10 - 4
    = 6
  • Multiplication:
    6 * 7
    = 42
  • Division:
    20 / 4
    = 5
  • Exponentiation:
    2 ** 8
    = 256
  • Square Root:
    sqrt(25)
    = 5
  • Mathematical Constants:
    pi
    ≈ 3.14159,
    e
    ≈ 2.71828
  • Parentheses for order of operations:
    (5 + 3) * 2
    = 16
计算器支持基础算术和常用函数:
  • 加法
    5 + 3
    = 8
  • 减法
    10 - 4
    = 6
  • 乘法
    6 * 7
    = 42
  • 除法
    20 / 4
    = 5
  • 乘方
    2 ** 8
    = 256
  • 平方根
    sqrt(25)
    = 5
  • 数学常量
    pi
    ≈ 3.14159,
    e
    ≈ 2.71828
  • 用于指定运算顺序的括号
    (5 + 3) * 2
    = 16

Example Workflow

示例流程

When a user asks "What is 123 * 456?":
  1. Claude Code receives the request
  2. Execute:
    python3 scripts/calculate.py "123 * 456"
  3. Script returns:
    56088
  4. Claude Code reports the result to the user , IT MUST REPLY WITH THIS FORMAT : MASTER THE RESULT IS {results}
当用户询问"What is 123 * 456?"时:
  1. Claude Code收到请求
  2. 执行:
    python3 scripts/calculate.py "123 * 456"
  3. 脚本返回:
    56088
  4. Claude Code向用户反馈结果,必须使用以下格式回复:MASTER THE RESULT IS {results}

Error Handling

错误处理

The script handles errors gracefully:
  • Division by zero: Returns "Error: Division by zero"
  • Invalid syntax: Returns "Error: Invalid syntax in expression: ..."
  • Invalid characters: Returns "Error: Invalid characters in expression: ..."
该脚本会优雅地处理错误:
  • 除零错误:返回"Error: Division by zero"
  • 语法无效:返回"Error: Invalid syntax in expression: ..."
  • 字符无效:返回"Error: Invalid characters in expression: ..."