I’m new to python and may not be very familiar with the detailed syntax rules.
Can i know how this error can be solved? It points to line 6,7,8 and i’m not sure what went wrong. Thanks!
def calculate_average_expenditure(a):
totalincome = 0
totalsavings = 0
count = 0
for item in a:
if (item['AGE2011'] >= 20 and item['AGE2011'] <= 30):
totalincome += item['INC2011']
totalsavings += item['SAV2011']
count += 1
totalexpenditure = totalincome-totalsavings
return totalexpenditure/count
EDIT:
Thanks, i got it working by tweaking how the method is called.
a={ 'uen': 's1234567h', 'AGE2011':21, 'INC2011':100, 'SAV2011':80}
b={ 'uen': 's1234567h', 'AGE2011':28, 'INC2011':300, 'SAV2011':100}
x=[a,b]
calculate_average_expenditure(x)
I guess the parameter
ais bound to a list of strings. Can you show how you callcalculate_average_expenditure(...)and and what...contains?