[Tutor] Need help with dict.calculation

Eve Kotyk e.kotyk@shaw.ca
Fri, 25 Jan 2002 00:32:24 +0000


> 
> Do you intend to use the contents of the dictionary after you've calculated
> the total calories? If not, it isn't really necessary to ask what type of
> food it is, nor even to keep the data in a dictionary. This is all you would
> need:
> 
> def gather_data():
>   portion=input("Enter number of portions: ")
>   cal_portion=input("Enter calories per portion: ")
>   return portion,cal_portion
> 
> def get_total_calories():
>   print "Enter all the foods you have eaten today."
>   total_calories=0        #It's now an integer instead of a dictionary, just
> to hold the number of calories
>   more=""
>   while more!="n":
>     portion,cal_portion=gather_data()
>     total_calories=total_calories+portion*cal_portion
>     more=raw_input("Do you want to continue? y/n: ")
>   print "Total calories: ",total_calories
> 
> But if you need to know what the names of the foods and such things
> afterwards... stick to your first approach.

Thank you.  I will look at this carefully too.  Actually what I'm trying
to do is essentially write a program that will be among other things a
dietary diary.  Because I'm a newbie to programming I'm taking it all in
small bits in order to learn.  So for starters I thought I'd write this
module as a dictionary because after this I would like to write this so
this can be done for each day of the week (like in the truckers
schedule) then I want to learn to write it to a file.  Eventually, this
should all be kept in a food database from which you can select items
rather then type them in and the calculations will not only be for
calories but will compare other food values (% protein, fats, carbs
etc.) to the recommended daily guidelines put out by the health dept. Of
course by this time it should have GUI interface and then I'd like it to
be accessible/usable from a website. =)  Nothing like thinking big eh?

E

> > --
> >
> > ekotyk
> >
> > http://members.shaw.ca/e.kotyk/virtualstudio.htm
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >

-- 

ekotyk

http://members.shaw.ca/e.kotyk/virtualstudio.htm