二手产品经理

二手产品经理

THIS IS RENO

JSON - 92天 - 在線學python100天

記錄#

  1. 今天是編碼練習,從一個天氣 API 獲取信息並列印。
  2. 不太清楚 weathercode 的具體含義,所以稍微修改了編碼要求。
  3. ChatGPT 教我如何找出出現最多次數的數字。

代碼#

main.py#

import requests, json
from collections import Counter

timezone = "GMT"
latitude = 51.5002
longitude = -0.1262

result = requests.get(
  f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone={timezone.upper()}"
)

user = result.json()
#print(json.dumps(user, indent=2))
#print("++++")
number_count = Counter(user['daily']['weathercode'])
most_common_number, count = number_count.most_common(1)[0]
print(
  f"天氣情況大部分都是{most_common_number}\n最高氣溫:{max(user['daily']['temperature_2m_max'])}-----最低氣溫:{min(user['daily']['temperature_2m_min'])}"
)
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。