Menu
Coddy logo textTech

Displaying Appropriate Results

Coddy의 Python으로 배우는 API 코스 레슨 — 10개 중 10번째.

challenge icon

챌린지

중급

이제 API 서버에 GET 요청을 성공적으로 보냈으므로, 중첩된 딕셔너리 값에 접근하여 우리가 원하는 특정 결과를 표시해 보겠습니다.

지침:

  1. https://wttr.in/London?format=j1로 GET 요청을 보냅니다.
  2. requests.get() 객체를 response라는 변수에 저장합니다.
  3. response.json()data라는 변수에 저장합니다.
  4. data["current_condition"][0] 안에 중첩된 현재 기상 조건에 접근하여 current라는 변수에 저장합니다.
  5. current["temp_C"]temperature라는 변수에 저장합니다.
  6. current["windspeedKmph"]wind라는 변수에 저장합니다.
  7. city라는 변수를 생성하고 "London"으로 설정합니다.
  8. 형식화된 메시지로 세 변수를 모두 출력합니다.

직접 해보기

import requests

# Step 1: Send GET request
response = # Your code here

# Step 2: Parse JSON response
data = # Your code here

# Step 3: Extract specific data
temperature = # Your code here
wind = # Your code here
city = # Your code here

# Step 4: Display results
print(f"City: {city}")
print(f"Temperature: {temperature}")
print(f"Wind: {wind}")

Python으로 배우는 API의 모든 레슨