You can download this code by clicking the button below.
This code is now available for download.
Calculates the average of a list of numbers. Returns 0 if the list is empty.
Technology Stack : os, re, json, sys, time, math, random
Code Type : Function
Code Difficulty : Intermediate
import os
import re
import json
import sys
import time
import math
import random
def calculate_average(numbers):
if not numbers:
return 0
return sum(numbers) / len(numbers)