我給出以下骨架讀取文件和相關信息
#This function helps calculate each transactions and return the final balance
#PARAMETERS:
#filename: the file going to be read, e.g. "transactions.txt", type: string
#namelist: a list containing all company names, type: list
#orgBalance: stores original balance for each company, type: nested list
#url: the url you are trying to fetch, type: string
#RETURN: current balance information (after all transactions), type: nested list
def transaction(filename, namelist, orgBalance, url):
#Call fetch(url) to get currency exchange information
exchange_info= fetch(url)
#Read each line from transactions.txt
myFile = open(filename,'r')
data=myFile.readlines()
#Check which company is conducting transactions
#If BUY, then convert the amount of foreign currency to USD
#and subtract the calculated amount
#If SELL, then convert the amount of foreign currency to USD
#and add the calculated amount
#Return current balance list
#your list should look like
#[['Acer', 481242.74], ['Beko', 966071.86], ...]
,我的數據列表如下:
transaction.txt
Gerdau BUY Brazilian Real: 17454
Gerdau SELL Botswana Pula: 31162
Acer BUY Danish Krone: 61376
Equifax BUY Icelandic Krona: 41983
Acer BUY Sri Lankan Rupee: 91659
Datsun SELL Trinidadian Dollar: 71248
Haribo BUY Indonesian Rupiah: 41548
Datsun SELL Saudi Arabian Riyal: 71627
namelist=['Acer', 'Beko', 'Cemex', 'Datsun', 'Equifax', 'Gerdau', 'Haribo']
orgBalance=[['Acer', 481242.74], ['Beko', 966071.86], ['Cemex', 187242.16], ['Datsun', 748502.91], ['Equifax', 146517.59], ['Gerdau', 898579.89], ['Haribo', 265333.85]]
and the url=https://www.cs.purdue.edu/homes/jind/exchangerate.html
我只是想知道,如果有人能通過這個步驟來引導我,我會得到前幾個部分,但是一旦我得到第三個評論我就會失去。我不知道如何處理搞清楚哪些公司購買或出售
歡迎來到StackOverflow。請閱讀並遵守幫助文檔中的發佈準則。 [主題](http://stackoverflow.com/help/on-topic)適用於此處。 SO不是教程服務,儘管您可能會在其他網站上找到幫助。 – Prune
這裏的問題目前還不清楚。 – eljefedelrodeodeljefe
我知道這個網站不是關於教程,所以我想我應該定義一個問題,在代碼中的第三個評論它說檢查哪個公司是傳導業務,那麼我將如何通過交易文本並找出並排序哪些公司買賣? –