请分析以下代码段中的错误并提供修复代码：
def calculate_average(list):
    total = 0
    for element in list:
        total += element
    avg = total / len(list)
return avg

list = [3, 7, 2, 8]
avg = calculate_average(list)
print("The average is: ", avg)
该代码段存在缩进错误，缩进不正确会导致代码运行时出现语法错误。同时，函数的返回语句不在函数的作用域内，应该加入到函数体内部。

修复代码如下：

```
def calculate_average(list):
    total = 0
    for element in list:
        total += element
    avg = total / len(list)
    return avg

list = [3, 7, 2, 8]
avg = calculate_average(list)
print("The average is: ", avg)
```