開始使用免費開始

有多少颶風來得早?

在本章中,你會使用一個清單,裡面是 1950 年到 2017 年在佛羅里達州登陸的颶風,共有 235 次。請查看變數 florida_hurricane_dates,其中包含所有這些日期。

大西洋颶風季正式開始於 6 月 1 日。自 1950 年以來,有多少颶風是在官方颶風季開始之前就在佛羅里達登陸?

本練習屬於課程

在 Python 處理日期與時間

檢視課程

練習說明

  • 完成 for 迴圈以遍歷 florida_hurricane_dates
  • 完成 if 敘述:若颶風在 6 月之前登陸,則將計數器(early_hurricanes)加一。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Counter for how many before June 1
early_hurricanes = 0

# We loop over the dates
for hurricane in ____:
  # Check if the month is before June (month number 6)
  if ____.____ < ____:
    early_hurricanes = early_hurricanes + 1
    
print(early_hurricanes)
編輯並執行程式碼