当前位置: 欣欣网 > 码农

Python简单实用计算器库

2024-06-07码农

大家好!今天给你们带来了简单python计算器库,库名jisuanqi可以用来批量完成基础计算。

安装:

pip install jisuanqi

实例:

from jisuanqi import*result1=jia(4561,456456,463,-5967)result2=jian(44,4564,555)result3=cheng(454,3352,3)result4=chu(99,7676,87)result5=cifang(2,14)result6=zuidazhi(2,56578,888)result7=zuixiaozhi(5672,5678,888)result8=pingjunzhi(5567,5657,2610)print("加:",result1)print("减:",result2)print("乘:",result3)print("除:",result4)print("次方:",result5)print("最大值:",result6)print("最小值:",result7)print("平均值:",result8)

输出:

加:455513减:-5075乘:4565424除:0.00014824531454960379次方:16384最大值:56578最小值:888平均值:13834

源码:

defjia(*numbers):return sum(numbers)defjian(*numbers):return numbers[0] - sum(numbers[1:])defcheng(*numbers): product = 1for num in numbers: product *= numreturn productdefchu(*numbers): result = numbers[0]for num in numbers[1:]: result /= numreturn resultdefcifang(base,exponent): result = base ** exponentreturn resultdefzuidazhi(*numbers):return max(numbers)defzuixiaozhi(*numbers):return min(numbers)defpingjunzhi(*numbers):return sum(numbers)