Displaying Appropriate Results
Coddy의 Python으로 배우는 API 코스 레슨 — 10개 중 10번째.
챌린지
중급이제 API 서버에 GET 요청을 성공적으로 보냈으므로, 중첩된 딕셔너리 값에 접근하여 우리가 원하는 특정 결과를 표시해 보겠습니다.
지침:
https://wttr.in/London?format=j1로 GET 요청을 보냅니다.requests.get()객체를response라는 변수에 저장합니다.response.json()을data라는 변수에 저장합니다.data["current_condition"][0]안에 중첩된 현재 기상 조건에 접근하여current라는 변수에 저장합니다.current["temp_C"]를temperature라는 변수에 저장합니다.current["windspeedKmph"]를wind라는 변수에 저장합니다.city라는 변수를 생성하고"London"으로 설정합니다.- 형식화된 메시지로 세 변수를 모두 출력합니다.
직접 해보기
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의 모든 레슨
3Weather Fetch API Program
API Connection to ServerGET Request to ServerDisplaying Appropriate Results