[Tutor] Need help with dict.calculation
Eve Kotyk
e.kotyk@shaw.ca
Fri, 25 Jan 2002 00:17:30 +0000
Thanks Danny,
> ###
> def get_total_calories():
> print "Enter all foods you have eaten today."
> more=""
> total_calories = {} ## <--- here's the change
Well that makes total sense, and I didn't have it defined properly. Its
still not working but I'm going
to continue withit for awhile. Want thing I do seem to be gifted with
is persistence.
> while more != "n":
> items, portion, cal_portion = gather_data()
> total_calories[items] = portion * cal_portion
> more = raw_input("Do you want to continue? y/n: ")
> for i in total_calories.values():
> total = total + i
> print "Total calories: ", total
This is giving me the total only of the last item entered. In another
version I'm at least getting a total for each item entered.
You know I can visualize this so well but I just don't know how to say:
Look at each item see what values it has and add up all those values in
to one number..in Python.
E