Something of Value 9/13 python help


#1

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
total = 0
for key in prices:


#2

1

In both the stock and prices dictionaries/objects
the pear property does NOT need an ending comma-,
as the comma-, is only used to separate properties from each-other.

prices = {
 "banana" : 4,
 "apple" : 2,
 "orange" : 1.5,
 "pear" : 3
}
stock = {
 "banana" : 6,
 "apple" : 0,
 "orange" : 32,
 "pear" : 15
}

tot_stock_val = 0
for key in prices:
    stock_val = 0
    print key,
    print "\tprice: %6.2f" % prices[key],
    print "\tstock: %4d" % stock[key],
    stock_val = prices[key] * stock[key]
    tot_stock_val += stock_val
print "\t"+key+"\tStV:" +format(stock_val, '9.02f')
print format(" ", '40s')+"------------ =====.== (+)"
print format(" ", '40s')+"Total\tStV:"+format(tot_stock_val, '9.02f')

total = 0
for key in prices:
    total += prices[key]
print total

#3

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]

total = 0
for key in prices:
print prices[key] * stock[key]
total += prices[key] * stock[key]

print total


#4

@devrunner19077,
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697
[extra's]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


#5

as is our heritage, 1 Create a variable called full and equal to zero
total = 0
2 Scroll down dictionaries prices.
for that called
for key in prices:
3 For each key in prices, multiply the number in prices by the number in stock
Total + = prices [key] * stock [key]
as they have the same key
4 displays the total (print total).
print total