[英]printing only the final iteration
i have written a code, it returns a list that is an update of a previous list.我写了一个代码,它返回一个列表,该列表是先前列表的更新。 i just need help figuring out how to return only the final value
我只需要帮助弄清楚如何只返回最终值
def doit(company,action,currency_code,amount,bank):
amount_in_usd = convert_to_usd(currency_code,amount)
newlist=[]
if action == "BUY":
amount = float(amount) - amount_in_usd
y=([company,amount])
newlist.append(y)
for index, values in enumerate(newlist):
bank[values[0]]=(bank[values[0]]+values[1])
if index == len(newlist) - 1:
return bank
if action == "SELL":
amount = float(amount) + amount_in_usd
y=([company,amount])
newlist.append(y)
for index, values in enumerate(newlist):
bank[values[0]]=(bank[values[0]]+values[1])
if index == len(newlist) - 1:
return bank
i need bank to be returned only once我只需要银行退还一次
Have a single return bank
statement a the end of the function, not conditional to anything.在函数的末尾有一个
return bank
帐单,不以任何条件为条件。 Remove both such statements as they currently are.删除当前的两个这样的语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.