有多少飓风来得更早?
在本章中,您将使用一个列表,包含 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)