我正在尝试制作一个程序,该程序在输入时接受字典并在银行账户中输出净金额。
我尝试了以下代码,但输出错误,我无法弄清楚原因:
netAmount = 0
bankDict = {'D':300,'D':300,'W':200,'D':100}
operations = bankDict.keys()
amount = bankDict.values()
for i in range(len(operations)):
if operations[i] == 'D': netAmount += amount[i]
elif operations[i] == 'W': netAmount -= amount[i]
else: pass
print netAmount
# OUTPUT: -100
输入不一定是字典。