(Sep-13-2021, 03:01 PM)trthskr4 Wrote: In the error at the bottom it shows Python 37, I only have 3.9. installed.Click down in left corner then Python: Select Interpreter will show up an choice Python 3.9
Now it use version the come with Microsoft Visual Studio stand alone,and not the same as Vs Code.
Some setup tips here VS Code from start
You most have
key.ini
in same folder as you run script,or give path where it is.Add input last not before the function,so like this.
import requests from configparser import ConfigParser def get_weather(city, api_key): api = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}" json_data = requests.get(api).json() return json_data def get_api_key(): config = ConfigParser() config.read('key.ini') api_key = config['key']['api_key'] return api_key if __name__ == '__main__': city = input("City where you are?: ") state = input("State where you are? ") city = f'{city},{state}' weather = get_weather(city, get_api_key()) print(weather['name']) print(weather['main']['temp']) print(weather[ 'weather'][0]['description'])Test.
# Version G:\div_code\answer\weather λ python -V Python 3.9.5 # Files in folder G:\div_code\answer\weather λ ls key.ini open_weather.py # Run G:\div_code\answer\weather λ python open_weather.py City where you are?: Houston State where you are? Texas Houston 296.82 mist