python - Returning Erroneous Values -


i'm new python, learning part of job training, started html , c/c++. advice how make segment work awesome!

def compute(tank_data): #in parenthesis variables want pass 1 def aggregates = {} list = [] tank in tank_data: #     sum = 0     max_value = 0     min_value = 1000     #standdev = 0     reading in tank_data[tank]:         sum = sum + float(reading)         '''max_value = round(max(float(reading)),2)         min_value = round(min(float(reading)),2)'''         if reading >= max_value:             max_value = float(reading)         else:             max_value = max_value         if reading <= min_value:             min_value = float(reading)         else:             min_value = min_value         #standdev     if tank in aggregates:         aggregates[tank]['avg'] = round(sum/len(tank_data[tank]),2) #computing , printing average simutaneously         aggregates[tank]['max'] = round(max_value,2)         aggregates[tank]['min'] = round(min_value,2)         #aggregates[tank]['stdev'] = round()     else:         aggregates[tank] = {}         aggregates[tank]['avg'] = round(sum/len(tank_data[tank]),2)         aggregates[tank]['max'] = round(max_value,2)         aggregates[tank]['min'] = round(min_value,2)         #aggregates[tank]['stdev'] = round() print aggregates 

i getting correct average values document (checked excel), first 3 max values correct (out of 6 run through here), , min values return '1000'.

when use commented out section:

'''max_value = round(max(float(reading)),2) min_value = round(min(float(reading)),2)''' 

i error 'float' object not iterable.

any appreciated. :)

use built-in functions of python:

def compute(tank_data):     aggregates = {}     list = []     tank, data in tank_data.iteritems():         numbers = [float(v) v in data]         total = sum(numbers)         max_value = max(numbers)         min_value = min(numbers)         info = {             'avg': round(total/len(numbers),2)              'max': round(max_value,2),             'min': round(min_value,2),         }         aggregates.set_default(tank, {}).update(info)     print aggregates 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -