Write function avg which calculates average of numbers in given list.

Difficulty: introductory

Starter code:

def find_average(array):
	

Solutions:
def find_average(array):
    return sum(array) / len(array) if array else 0

def find_average(array):
    return 0 if not array else sum(array) / len(array)


def find_average(array):
    try:
        return sum(array) / len(array)
    except ZeroDivisionError:
        return 0

def find_average(array):
    if not array:
        return 0

    class SafeFloat(object):
        def __init__(self, val):
            super(SafeFloat, self).__init__()
            self.val = val

        def __eq__(self, float_val):
            # let me fix your comparisons..
            def isclose(a, b):
                return abs(a - b) < 0.00000001
            return isclose(self.val, float_val)

        def __str__(self):
            return str(self.val)

    from numpy import mean
    return SafeFloat(mean(array))


def find_average(array):
    return sum(array) / (len(array) or 1)

def find_average(array):
    return 0 if not array else sum(array) / len(array)

def find_average(array):
    if len(array) != 0:
        return sum(array) / len(array)
    else:
        return 0

def find_average(array):
    return 0 if len(array) == 0 else sum(array) / len(array)

from numpy import mean as find_average

def find_average(a):
    return sum(a)/len(a) if a else 0

def find_average(array):
  mean=0
  if len(array)== 0:
    return mean
  sum=0
  for i in array:
    sum= sum+i
  mean= sum/(len(array))
  return mean


def find_average(array):
    return sum(array)/len(array) if len(array) > 0 else 0

def find_average(array):
    sum = 0
    for num in array:
        sum += num
    try:
        return sum/len(array)
    except ZeroDivisionError:
        return 0

find_average = lambda x: sum(x)/len(x)

def find_average(arr):
    return (sum(arr)/len(arr) if len(arr) != 0 else 0)

def find_average(array):
    if not array:
        return 0
    else:
        sum = 0
        for i in array:
            sum += i
        return sum/len(array)


def find_average(A):
    return sum(A)/len(A) if A else 0

def find_average(array):
    return sum(array)/len(array) if len(array) else 0

def find_average(array):
    if len(array) == 0:
        return 0
    i = 0
    tot = 0
    while i < len(array):
        tot = tot + array[i]
        i += 1
    return (tot/len(array))

def find_average(array):
    return (0 if array == [] else sum(array) / len(array))


def find_average(array):

    if array == []: return 0
    return sum(array)/len(array)

def find_average(array):
    
    sum=0
    average=0
    
    if (len(array)>0):
    
        for number in array:
            sum+=number    
    
    else:
        return 0
    
    average=sum/len(array)
    
    return average

find_average = lambda array: sum(array) / len(array) if array else 0

def find_average(array):
    if len(array) != 0:
        return sum(array)/len(array)
    return 0

def find_average(array):
    if len(array) < 1:
        return 0
    else:
        return sum(array)/len(array)

def find_average(a):
    for i in a:
        i += i
        y = i/len(a)
    return y# create an array called websites that has "codewars" as its only value

find_average = lambda x:2 # ;)

def find_average (*array):
    return 2

import numpy as np


def find_average(array):
    return np.mean(array)


def find_average(arr):
    return sum(arr) // len(arr) 

def find_average(array):
    if not len(array): return 0
    else: return sum(array) / len(array)

def find_average(array):
    tot = 0
    if array:
      for n in array:
          tot += n
      return tot / len(array)
    else:
      return 0

find_average = lambda array : sum (array) / len (array) if (array != []) else 0;

def find_average(arr):
    return sum(arr)/(len(arr) or 1)

find_average = lambda x: sum(x)/len(x) if len(x) > 0 else 0

find_average=lambda arr: sum(arr)/(len(arr) or 1)

# create an array called websites that has "codewars" as its only value
def find_average(num):
    sum = 0
    for i in num:
        sum += i
        average = sum/len(num)
    return average


# create an array called websites that has "codewars" as its only value
def find_average(arr):
    s=0
    l=len(arr)
    for i in arr:
        s=s+i
    return s//l

def find_average(array):
    k = sum(array) / len(array)
    return k
    
    # create an array called websites that has "codewars" as its only value


find_average = lambda lst: sum(lst) // len(lst)

# create an array called websites that has "codewars" as its only value
def find_average(n):
    num = 0
    for i in n:
        num += i
    return(num/ len(n))
        
        


# create an array called websites that has "codewars" as its only value
def find_average(n):
    i=0
    j=0
    for number in n:
        i += number
        j += 1
    return (i/j)

# create an array called websites that has "codewars" as its only value
def find_average(n):
    average = 0
    for i in n:
        average += i
    return average/len(n)

# create an array called websites that has "codewars" as its only value
def find_average(n):#
    total = 0
    for i in n:
        total += i
    return total / len(n)


import numpy
def find_average(l):
    return numpy.mean(l)

def find_average(numbers):
    total = 0
    for i in numbers:
        total = total + i
    return total/len(numbers)

def find_average(args):
    sum = 0
    for i in args:
        sum += args[i - 1]
    return sum / len(args)

import statistics;

def find_average(a):
    return (sum(a)/len(a));

# create an array called websites that has "codewars" as its only value


def find_average(listt):
    for i in listt:
        return sum(listt)/len(listt)
        


def find_average(a):
    for i in a:
        return sum(a) / int(len(a))

def find_average(arr):
    x=len(arr)
    sum=0
    
    for i in range(x):
        sum=sum+arr[i]
    
    return sum/x

# create an array called websites that has "codewars" as its only value
def find_average(lst):
    count = 0
    average = 0
    for i in lst:
        count += i
    average = count / len(lst)
    return average

def find_average(ar):
    return sum(ar)//len(ar)

def find_average(arr):
    return sum(arr[:]) / len(arr)


# create an array called websites that has "codewars" as its only value
def find_average(list):
    n = len(list) 
    return sum(list) / n

def find_average(num):
    avg = sum(num)/len(num)
    return avg

def find_average(arr):
    res = 0
    for elem in arr:
        res += elem
    return res/len(arr)

def find_average(n):
    aver = 0
    for i in range(len(n)+1):    
        aver +=i
    return int(aver/len(n))  





def find_average(nums):
    return ((nums[0] + nums[-1]) / 2)

# create an array called websites that has "codewars" as its only value
def find_average(n):
    sum_n = 0
    for i in n:
        sum_n += i
    return sum_n // len(n) 

def find_average(a):
    s=0
    avg=0
    for i in a:
        s+=i
    
    avg=s/len(a)
    return avg

from numpy import mean
def find_average(x):
    return mean(x)

def find_average(lst):
    sum = 0
    for nb in lst:
        sum += nb
    return sum / len(lst)

def find_average(arr):
    sum=0
    
    if 0==len(arr):
        return 0;
    
    for num in arr:
        sum+=num
        
    sum=sum/len(arr)
    
    return sum

# create an array called websites that has "codewars" as its only value
def find_average(lst):
    sum = 0
    for i in lst:
        sum+= i
    return int(sum / len(lst))


def find_average(list):
    avg = 0
    for i in range(len(list)):
        avg += list[i]
    return avg / len(list)
# create an array called websites that has "codewars" as its only value


# create an array called websites that has "codewars" as its only value


def find_average(array):
    total = 0
    for n in array:
        total += n
    return total / len(array)    


def find_average(array):
    return sum(number for number in array)/len(array)

def find_average(nums):
    sum = 0
    for i in nums:
        sum += i
    total = sum / len(nums)
    return total

def find_average(arr):
    websites = ["codewars"]
    return sum(arr)/len(arr)

def find_average(array):
    num = 0
    for x in array:
        num += x
    return num/len(array)

find_average = __import__("statistics").mean

import numpy

find_average = numpy.mean

def find_average(my_list):
    sum = 0
    count = 0
    
    for number in my_list:
        count = count + 1
        # count += 1
        sum = sum + number
        # sum += number
        
    average = sum / count
        
    return average

# sum = 5, 13, 15
# count = 1, 2, 3


def find_average(values):
    sum = 0
    for n in values:
        sum += n
    return sum / len(values)

websites = ['codewars']

def find_average(x):
    average = sum(x) / len(x)
    
    return average




def find_average(nums):
    count = 0
    total = 0
    for i in nums:
        count += 1
        total += i
    return (total/count)

def find_average(list):
    c=0
    for i in list:
        i+=i
        c+=1
    return i/c

# create an array called websites that has "codewars" as its only value
def find_average(values):
    sum_of_values = 0
    i = 0
    for value in values:
        i += 1
        sum_of_values += value
    return sum_of_values / i

from functools import reduce

def find_average(arr):
    return reduce(lambda a, b: a + b, arr) / len(arr) 

def find_average(arr):
    if arr:
        return sum(arr) / len(arr)

websites = ['codewars'] # create an array called websites that has "codewars" as its only value

def find_average(arr):
    count = 0
    sum = 0
    for number in arr:
        count += 1
        sum += number
    return sum / count


def find_average(x):
    y = 0
    for i in range(len(x)):
        y = y + x[i]
    return (y/len(x))

def find_average(a):
    sum=0
    for i in a:
        sum+=i
    return sum/i

# create an array called websites that has "codewars" as its only value
def find_average(lst):
    ag = 0
    for i in lst:
        ag += i
    return ag / len(lst)


# create an array called websites that has "codewars" as its only value
def find_average(number):
    for i in range (len(number)):
        return(sum(number)/len(number))
        


websites = {'codewars'}
def find_average(n): return sum(n)/len(n)

def find_average(nums):
    return sum(nums) // len(nums)

# create an array called websites that has "codewars" as its only value
def find_average(websites):
    count = 0
    for i in websites:
        count += i
    return count // len(websites)


find_average = lambda x: x and sum(x)/len(x)

# create an array called websites that has "codewars" as its only value
def find_average(whattheheck):
    return sum(whattheheck) / len(whattheheck)



def find_average(num_list):
    return sum(num_list) / len(num_list)


def find_average(list):
    average = len(list)/2
    return round(average)

codewars = ["a","b","c"]
def find_average(codewars):
    average = (codewars[0]+codewars[1]+codewars[2])/3
    return average

def find_average(a_list):
    return sum(a_list)/len(a_list)

def find_average(n):
    import numpy
    return numpy.mean(n)

def find_average(lst):
    results = sum(lst)/len(lst)
    return results

# create an array called websites that has "codewars" as its only value
def find_average(list):
    sum = 0
    for i in range(len(list)):
        sum += list[i]
        
    total = sum / len(list)
    return total

def find_average(a):
    count = 0
    for i in a:
        count += i
    return count/len(a)

def find_average(args):
    return sum(args) / len(args)