+ 1
User input as dictionary key?
here's the code: my_address=("Enter address: ") my_params = {'address': 'my_address', 'lang': 'en' } except this doesn't work as I'm sure you can guess. So how then can I assign the variable my_address to the dictionary key value? I'm working on an address to geotag script, where the user enters their address and receive their latitude, longitude from Google Maps. Thanks!
3 ответов
+ 1
and yes that did work. and I had tried that but the actual problem was I put the field separator ' : ' on the wrong side of the quotes in my dictionary. ie it read 'address:' my_address, instead of 'address': my_address.
thanks again
0
First off, your variable my_address will not ask for or store any user input. The way it is currently written, you are only assigning a tuple containing a string to the variable. You need to use the input() function to get user input.
Secondly, to answer your question, you are currently mapping the string 'my_address' to the key 'address'. However, you want to be assigning the variable my_address, which contains a string of user input. Drop the quotations from 'my_address' in the dictionary definition.
0
thanks for the reply! I actually have the user input part written correctly in the code (my_address = input("Enter street address: "). Due to the limited char length of the question box I just wrote it like that hoping someone would figure out what I was trying to do.
So dropping the quotes should do it then huh? Seems like I've tried that but maybe not. Thanks again