+ 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!

11th Feb 2017, 4:22 PM
Aaron Nelson
Aaron Nelson - avatar
3 Answers
+ 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
12th Feb 2017, 1:40 PM
Aaron Nelson
Aaron Nelson - avatar
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.
12th Feb 2017, 4:05 AM
Wesley Duckett
Wesley Duckett - avatar
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
12th Feb 2017, 1:26 PM
Aaron Nelson
Aaron Nelson - avatar