美文网首页
用python写一个单一计算器程序

用python写一个单一计算器程序

作者: 一个小运维 | 来源:发表于2021-05-20 20:14 被阅读0次

用python写一个单一计算器程序:

print("直接回车可以结束输入")
L=[]
while True:
    x = input("请你输入数字:")
    if x == "":
        break
    L.append(int(x))
print(L)
def add():
    x=0
    for j in L:
        x+=j
    print(f"数字{L}相加的和是{x}")
def subtract():
    x=L[0]
    for j in L[1:]:
        x-=j
    print(f"数字{L}相减的差是{x}")
def multiply():
    x=L[0]
    for j in L[1:]:
        x*=j
    print(f"数字{L}相乘的积是{x}")
def divide():
    x=L[0]
    for j in L[1:]:
        x/=j
    print(f"数字{L}相除的商是{x}")
fuhao=input("请你选择运算符号 '+ - * /'")

if fuhao == "+":
    add()
if fuhao == "-":
    subtract()
if fuhao == "*":
    multiply()
if fuhao == "/":
    divide()

相关文章

网友评论

      本文标题:用python写一个单一计算器程序

      本文链接:https://www.haomeiwen.com/subject/atbbjltx.html