I have only been working with python for a few months, so sorry if I am asking a stupid question. I am having a problem calling a dictionary name using a variable.
The problem is, if I use a variable to call a dictionary & [] operators, python interprets my code trying to return a single character in the string instead of anything within the dictionary list.
To illustrate by an example ... let's say I have a dictionary list like below.
USA={'Capital':'Washington',
'Currency':'USD'}
Japan={'Capital':'Tokyo',
'Currency':'JPY'}
China={'Capital':'Beijing',
'Currency':'RMB'}
country=input("Enter USA or JAPAN or China? ")
print(USA["Capital"]+USA["Currency"]) #No problem -> WashingtonUSD
print(Japan["Capital"]+Japan["Currency"]) #No problem -> TokyoJPY
print(China["Capital"]+China["Currency"]) #No problem -> BeijingRMB
print(country["Capital"]+country["Currency"]) #Error -> TypeError: string indices must be integers
In the example above, I understand the interpreter is expecting an integer because it views the value of "country" as a string instead of dictionary... like if I put country[2] using Japan as input (for example), it will return the character "p". But clearly that is not what my intent is.
Is there a way I can work around this?