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. Remove both such statements as they currently are.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.