开始使用免费开始使用

计算平均值

接下来,您的任务是检查一家餐厅在晚餐高峰时段(18:00–21:00)的送餐时长,以优化平台性能。您有一个以分钟为单位的 delivery_times 列表。

让我们使用内置函数来计算平均送达时间。

本练习是课程的一部分

Python 中级:面向开发者

查看课程

练习说明

  • 计算平均送达时间,并保存为 average_time
  • average_time 四舍五入到小数点后两位,并保存为 average_rounded

交互式实操练习

通过完成这段示例代码来试试这个练习。

delivery_times = [19, 25, 35, 40, 28, 32, 29, 31]

# Find the average delivery time
average_time = ____(delivery_times) / ____(delivery_times)

# Round the average delivery time to two decimal places
average_rounded = ____(____, ____)

print("Average delivery time:", average_rounded)
编辑并运行代码