Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Cyborg-Model-Z/46371aeed99d376060fc18ca297ddc60 to your computer and use it in GitHub Desktop.

Select an option

Save Cyborg-Model-Z/46371aeed99d376060fc18ca297ddc60 to your computer and use it in GitHub Desktop.
average_array
input_arrays = [[1, 30, 2], [21, 20, 20], [1, 2, 3]]
def round_down_to_twenty(input_arrays):
for array in input_arrays:
for x in array:
if x >=20:
x = 20
else: x=x
def average_array(arrays):
nr=0
for array in input_arrays:
for element in array:
nr=nr+element
print(nr/(len(array)))
nr=0
average_array(round_down_to_twenty(input_arrays))
@Cyborg-Model-Z
Copy link
Author

@dwms0danr see above

@dwms0danr
Copy link

dwms0danr commented Jun 13, 2019

-- didn't have 3rd function. Here is my re-work of 1st 2
-- I tried to comment a bit also

input_arrays = [[1, 30, 2], [21, 20, 20], [1, 2, 3, 9], [10,11,12,40,41]]
input_arrays_1 = []

def round_down_to_twenty(input_arrays):

    print ('start of "round_down_to_twenty"')
    '''ceeate vaiable x to get values that need to be changed iv >= 20'''
    x=0
    '''list a1 will hold results whereby value is assigned 20 if it is >= 20'''
    a1=[]
    for array in input_arrays:
        ''' getting each element if the array list'''
        for x in array:
            if x >=20:
                x = 20
            ''' append value to new list named a1'''
            a1.append(x)
        print('New list containing values rounded down to 20.', a1)
        input_arrays_1.append(a1)
        a1=[]
    print ('')
    print ('starting array.', input_arrays)
    print ('  ending array.',input_arrays_1)
    print ('end of "round_down_to_twenty"')

def average_array(input_arrays):
    input_arrays_1=[]
    print ('\nStart of "average_array"')
    nr=0
    for array in input_arrays:
        for element in array:
            nr=nr+element
        print('Average of each element in the input_arrays list.', nr/len(array))
        input_arrays_1.append(nr/len(array))
        nr=0
    print (input_arrays_1)
    print ('End of "average_array"')

round_down_to_twenty(input_arrays)

average_array(input_arrays)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment