编写一个程序,根据控制台输入的所有事务日志计算银行帐户的净金额

  • 编写一个程序,根据控制台输入的所有事务日志计算银行帐户的净金额(使用while 循环,直到用户输入“END”才退出事务日志输入,并输出最终银行账户的净金额)。
  • 事务日志格式中D表示存款,而W表示提款,操作过程如下所示:

#!/usr/bin/nve python
# coding: utf-8

print(f"\n{' d:存,w:取,end:结束输入 ':=^39}\n")
result = 0

while True:
    input_s = input(f'\n请输入(如w 100):')
    if input_s[0] == 'd':
        result += int(input_s.split()[1])
    elif input_s[0] == 'w':
        result -= int(input_s.split()[1])
    elif input_s[:3] == 'end':
        print(f"\n{'':~^50}\n{'您的账户余额:':>18}{result}\n{'':~^50}\n")
        break
    else:
        print(f"\n{' 输入错误!':~^45}\n")

img