编写一个程序，计算给定列表中所有数字的平均值。如果列表为空，则返回0。


def calculate_average(nums):
"""Return the average of the given numbers."""
# TODO: implement the average calculation logic

print(calculate_average([1, 2, 3, 4, 5])) # should print 3.0
print(calculate_average([])) # should print 0
以下是实现计算平均值的代码：

```
def calculate_average(nums):
    if len(nums) == 0:
        return 0
    return sum(nums)/len(nums)

print(calculate_average([1, 2, 3, 4, 5])) # should print 3.0
print(calculate_average([])) # should print 0
```