小编Mic*_*ens的帖子

Python计算器 - 隐式数学模块

我时不时地得到计算的答案.因为我通常有一个终端屏幕打开,这是我提出这样的数学问题的自然场所.

Python交互式shell很适合这个目的,前提是你想要输入另一个shell只是为了以后必须退出它.

有时虽然最好立即从命令行获得答案.Python有-c命令选项,我发现它在处理单个命令和返回结果时很有用.我编写了以下bash shell脚本来使用它:

#!/bin/bash
# MHO 12-28-2014
#
# takes a equation from the command line, sends it to python and prints it
ARGS=0
#
if [ $# -eq 1 ]; then
  ARGS=1
fi
#
if [ $ARGS -eq 0 ]; then
  echo "pc - Python Command line calculator"
  echo "ERROR: pc syntax is"
  echo "pc EQUATION"
  echo "Examples"
  echo "pc 12.23+25.36      pc \"2+4+3*(55)\""
  echo "Note: if calculating one single equation is not enough,"
  echo "go elsewhere and do …
Run Code Online (Sandbox Code Playgroud)

python bash calculator command-line-interface

10
推荐指数
1
解决办法
1519
查看次数

标签 统计

bash ×1

calculator ×1

command-line-interface ×1

python ×1