「 WeatherHack のAPI 」を使用しているのですが、エラー文が出てしまい、情報を出力できず困りました。
最初、天気の情報や日にちの情報を取得して出力するところまではできたので、最低気温と最高気温を取得して出力しようと思い、for文のあとのif-else文を加えたら、エラー文が出始めて取得できませんでした。
エラー文を見たところ「TabError: inconsistent use of tabs and spaces in indentation」と出たので、指定された文のインデックスが間違っていると思い、一旦コードを消して書き直したり修正したのですが、それでもエラーが出てしまうので、私にはどこが間違っているのかわかりません。色々ネット検索をして構文が間違っていないか調べたのですが、やっぱりわからないので、どなたかアドバイスくださるとうれしいです、、
ちなみにエラー文は
「 File "~~~.py", line 17
print(weather['date'] + ':' + weather['dateLabel'] + ':' + weather['telop'])
TabError: inconsistent use of tabs and spaces in indentation 」
です。
python
1#!/usr/bin/env python 2# coding: utf-8 3 4import requests 5import json 6 7def get_weather(): 8 url = 'http://weather.livedoor.com/forecast/webservice/json/v1' 9 payload = {'city': '400040'} 10 data = requests.get(url, params = payload).json() 11 12 print(data['title']) 13 14 15 for weather in data['forecasts']: 16 17 print(weather['date'] + ':' + weather['dateLabel'] + ':' + weather['telop']) 18 19 if weather['temperature']['min'] is None: 20 print("最低気温無し") 21 else: 22 print(weather['temperature']['min']['celsius']) 23 24 if weather['temperature']['max'] is None: 25 print("最高気温無し") 26 else: 27 print(weather['temperature']['max']['celsius']) 28 29 return 30 31if __name__ == '__main__': 32 get_weather()
<開発環境>
windows 10
Python 3.7.1
回答1件
あなたの回答
tips
プレビュー