Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Two Dictionaries and a Sum!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Chris Angelico, post: 5093509"] Let me reword your problem a little, maybe it'll be a bit clearer. You're trying to calculate the total value of all stock on hand, eg for insurance purposes. That's not 24 bananas, that's $24 of bananas. And the part you want now is to get the total value of your entire stock. Great! You're very close to there... .... you just need to accumulate a sum. Since this is almost certainly homework, I won't give you the answer, but here are a few pointers: * You'll need a single variable (I use the term sloppily, Python doesn't actually have variables per se) which will collect the final total. * Inside your loop, you're currently printing out an int/float with the value of the current item. Just add it onto your accumulator. * Python will happily work with integers and floats together, so you can just do what's obvious and it'll work. See where that takes you. Have fun! :) ChrisA [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Two Dictionaries and a Sum!
Top