事务日志格式中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")