pythonbook/Python 基础教程/1.5.7 D练习4.py

19 lines
598 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 4.题:编写一个程序,根据控制台输入的事务日志计算银行帐户的净金额。 事务日志格式如下所示: D 100 W 200
# D表示存款而W表示提款。 假设为程序提供了以下输入: D 300 D 300 W 200 D 100 然后,输出应该是: 500
netAmount = 0
while True:
print("请输入:")
s = input()
if not s:
break
values = s.split(" ")
operation = values[0]
amount = int(values[1])
if operation=="D":
netAmount+=amount
elif operation=="W":
netAmount-=amount
else:
pass
print (netAmount)