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="Roy Smith, post: 5093536"] Hmmm, homework for a class? I suspect what you're trying to say is that bananas cost BTC 4 each, and since you've got 6 bananas, you've got BTC 24 worth of bananas, yes? And now you want to find the total value of your fruit supply? So far, so good. A couple of things you may have noticed along the way: 1) Your orange unit price was a float, so the total value of all your oranges is a float as well. That's how math works in Python. 2) The keys are presented in random order. To make the output easier to interpret, you might want to do: print key, prices[key]*stock[key] The most straight-forward way would be something like: total = 0 for key in prices: fruit_subtotal = prices[key]*stock[key] total += fruit_subtotal print key, fruit_subtotal print total There are better ways to do this in Python, but start like this and get that to work. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Two Dictionaries and a Sum!
Top