Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # arrays
- # list or table of related items
- # 1 dimensional array = > list
- # index 0 1 2 3 4 always starts at zero 0
- scores = [45,52,63,24,34]
- print (len(scores))
- print("1st item",scores[0])
- print("last item using direct index",scores[4])
- print("last item using length index",scores[(len(scores))-1]) # if you see a -1 in an exam be careful
- print("last item using direct index from the other end",scores[-1])
- # 2 dimensional array
- # currency exchange rates
- # https://www.exchangerates.org.uk/
- """
- 0 1
- 0 GBP EUR 1.1897 Pounds to Euros
- 1 GBP USD 1.3475 Pounds to Dollars
- 2 GBP NZD 1.9846 Pounds to New Zealand Dollars
- """
- # array = list of lists in python
- # list 0 1 2
- # item 0 1 0 1 0 1
- exchange_rates = [["EUR", 1.1897],["USD", 1.3475],["NZD", 1.9846]]
- print(len(exchange_rates))
- print("1st item",exchange_rates[0])
- print("1st item",exchange_rates[0][1])
- cash_held = float(input("how much cash have you got >> ")) # need to be a float for decimal amount
- buy_currency = input("what currency do you want to buy >> ") # enter the code
- currency_amount = 0 # asign exchaged amount
- for each_item_index in range(len(exchange_rates)):
- #print(each_item_index) testing
- if exchange_rates[each_item_index][0] == buy_currency:
- currency_amount = cash_held * exchange_rates[each_item_index][1]
- print(str(cash_held) + " would buy you " + str(currency_amount) + " " + buy_currency ) # easier way to do this line
- print(cash_held," would buy you ",currency_amount,buy_currency ) # easier way to do this line
- """
- EXTENSION IDEAS
- 1. add more currencies
- 2. add to convert the other way say you had dollars and wanted GBP ( multiply by 1/ rate)
- 3. add a while loop so keeps going until a key word ("Quit" say) is entered for the country code
- 4. export to an offline file, as a data backup extension
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement