Question


#1

Regarding lesson “A Day at the Supermarket”
exercise 9 - Something of Value

total = 0
for k in prices:
print prices[k] * stock[k]
total = total + (prices[k] * stock[k])

why do I need the ( ) brackets? shouldn’t * always be calculted first than +.
Thanks


#2

Hi @valente5,

In fact, you do not need the parentheses here, due to the order of precedence of operations to which you alluded …

total = total + (prices[k] * stock[k])

#3

ok, thanks… code academy wasn’t accepting it as a correct answer.


#4

Are you sure that it was that line that Codecademy considered to be the issue? What message did you receive that indicated that there was a problem?


#5

I don’t remember anymore… no worries, thanks for the help


#6