달력 월별 사건 수 세기
허리케인은 플로리다에서 연중 어느 때나 상륙할 수 있어요. 이미 이야기했듯이, 어떤 달은 다른 달보다 허리케인이 더 많이 발생합니다.
florida_hurricane_dates를 사용해, 한 해 동안 플로리다의 허리케인이 월별로 어떻게 분포하는지 살펴보겠습니다.
카운트를 저장할 딕셔너리 hurricanes_each_month를 만들고 초기값을 0으로 설정해 두었습니다. 허리케인 목록을 순회하면서 해당 월의 hurricanes_each_month 값을 1씩 올리고, 결과를 출력하세요.
이 연습은 강의의 일부입니다
Python에서 날짜와 시간 다루기
연습 안내
for루프 안에서:- 그 허리케인의 월을
month변수에 할당하세요. - 해당 월의
hurricanes_each_month값을 1만큼 증가시키세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# A dictionary to count hurricanes per calendar month
hurricanes_each_month = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6:0,
7: 0, 8:0, 9:0, 10:0, 11:0, 12:0}
# Loop over all hurricanes
for hurricane in florida_hurricane_dates:
# Pull out the month
month = hurricane.____
# Increment the count in your dictionary by one
hurricanes_each_month[month] ____
print(hurricanes_each_month)