G,Day everyone :)
so my class has been given a assignment to make a currency converter. what we are asked to do is. read data from csv file and get a specific set of exchange rates from a certain date listed in the csv file. made using a function so we then return an array that has to look like "unit,rate,unit,rate" unit = currency code "HKD code = Hong Kong Dollor" rate is the rate at which the useramount is exchanged by "useramount = float of "numbers" and rate is gathered from returned array. output will end up being useramount * rate. also the converter is split across 2 python files also. reading and converting in one file and getting the user input data and asking if they would like to convert again the the 2nd python file. just want to note that we are not to use the csv module.
I've read the csv and got the array returned as it needs to be, building of the array could be better but unsure of how to do that, some advice for that would be great(thats not my main problem). my main problem is trying to get the rate i need from the returned array to be used in the conversion. i want to able to check if the usercode == "HKD" in array and +1 to "HKD" position(as this is where the exchange rate for that currency code lives) and set to a variable to be used in the conversion of the inputed useramount.
i hope all of the above makes sense, obviously i'm looking not for the answer i'm looking for something to get me on the right track. Thanks in advance for taking the time to read all this and i really do appreciate any advice or suggestions.
all the code i have so far is listed below.
so my class has been given a assignment to make a currency converter. what we are asked to do is. read data from csv file and get a specific set of exchange rates from a certain date listed in the csv file. made using a function so we then return an array that has to look like "unit,rate,unit,rate" unit = currency code "HKD code = Hong Kong Dollor" rate is the rate at which the useramount is exchanged by "useramount = float of "numbers" and rate is gathered from returned array. output will end up being useramount * rate. also the converter is split across 2 python files also. reading and converting in one file and getting the user input data and asking if they would like to convert again the the 2nd python file. just want to note that we are not to use the csv module.
I've read the csv and got the array returned as it needs to be, building of the array could be better but unsure of how to do that, some advice for that would be great(thats not my main problem). my main problem is trying to get the rate i need from the returned array to be used in the conversion. i want to able to check if the usercode == "HKD" in array and +1 to "HKD" position(as this is where the exchange rate for that currency code lives) and set to a variable to be used in the conversion of the inputed useramount.
i hope all of the above makes sense, obviously i'm looking not for the answer i'm looking for something to get me on the right track. Thanks in advance for taking the time to read all this and i really do appreciate any advice or suggestions.
all the code i have so far is listed below.
#Begging of finance.py - python file 1 def read_file(): #Reading in csv file as "csvfile" with open("f11hist.csv", "r") as csvfile: #Iterating over the entire csvfile a line at a time for line in csvfile: #Checking for 28-Sep-2018 in line for later use if "28-Sep-2018" in line: #splitting line into separate values and creating a array date_data = line.split(",") #Breaking the loop break #creating a temporary list of the currency codes x = "JPY GBP NZD HKD CAD" #splitting the temporary list into separate values currency_codes = x.split(" ") #example of list outcome """ ["JPY", "GBP", "NZD", "HKD", "CAD"] - currency_codes ["81.96","0.5519","1.0921","5.6525","0.9405"] - date_data """ #end result of list for the exchanging currencies exchange = [ currency_codes[0], date-data[4], # JPY & Exchange Rate currency_codes[1], date-data[7], # GBP & Exchange Rate currency_codes[2], date-data[11], # NZD & Exchange Rate currency_codes[3], date-data[18], # HKD & Exchange Rate currency_codes[4], date-data[19] # CAD & Exchange Rate ]; #returns the list for use return exchange def currency_convert(amount, rate): return amount * rate #Begging of Running_Converter.py - python file 2 from finance import read_file from finance import currency_convert def user_convert(): print(""" ########################## ### Currency Converter ### ########################## Please select one of the following currency codes -JPY- -GBP- -NZD- -HKD- -CAD-""") usercode = input("Please enter a Country code: ") useramount = float(input("Please enter the amount you wish to: $")) for line in read_file(): if line in usercode: print(line)