平均行程時間
在這個資料集中,W20529 總共進行了 291 趟行程。平均每趟要花多久?你可以用 Python 內建的 sum() 和 len() 來計算。
根據上一題的結果,資料已載入為 onebike_durations。每個元素代表這台單車離開停靠架的秒數。
本練習屬於課程
在 Python 處理日期與時間
練習說明
- 計算
onebike_durations中所有行程的total_elapsed_time。 - 計算
onebike_durations的number_of_trips。 - 用
total_elapsed_time除以number_of_trips,得到平均行程長度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# What was the total duration of all trips?
total_elapsed_time = ____(____)
# What was the total number of trips?
number_of_trips = ____(____)
# Divide the total duration by the number of trips
print(____ / ____)