'type list doesn't define __round__ method

Trying to round the output and have tried placing round() in several places and always get the same error.

def stock_change(data):
    # YOUR CODE
    import numpy as n

    m=(len(data)-1)//2
    lower=data[:m+1]
    upper=data[m+1:]
    ml=n.median(round(lower,1))
    mu=n.median(round(upper,1))
    if ml>mu:
      print('average stock value has decreased')
    if ml<mu:
      print('average stock value has increased')
    if ml==mu:
      print('average stock value is unchanged')

print([ml,mu])

example of code giving me the error



Solution 1:[1]

Round does not accept an iterator. If you're trying to calculate the median of the list and then round that value (as I would expect you are trying to do) you can use:

ml=round(n.median(lower))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1