Instructions not complete and confusing


Once again, I find the instructions not complete and confusing in outlining the requirements for the code. Looking for some help with this assignment. Oh and how do you do screen shots on this forum?

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

Not getting the expected result, confused. Please need code to be reviewed
Not getting the expected result, confused. Please need code to be reviewed
Not getting the expected result, confused. Please need code to be reviewed

The print statement is indented so repeats in the loop. Remove indentation from that line.


It might be several different ways in Your're using a Mac it Could be a Command + shift + 4. If your're using a windows try and search your comp. for the "snip it tool", But I don't if those methods will let you scroll and capture the entire forum. The pluses are to symbolize the next button to press (I say that because I got confused when I heard about that.


Unless it is to show something that cannot be easily represented in plain text, screenshots should be avoided. It makes it much easier to test and and correct raw code.


Is that just for this coding environment? I ask because I tried taking the code from Codecademy and pasted it into a Python code editor and got an error message.


This environment is Python 2. There are differences in Python 3, the print statement, for starters. In Python 3 it is now a function, so must be called as a function.

print ("some content")


Ok, I see that my code has already been formatted to a screen shot. When I paste my code, it just paste's the raw text and doesn't show the indentations. But now I see that it does that after my code is submitted.


Removed the indentation and it still didn't work. Not sure where the issue is. It also says that it did not print the correct totals. Scratching my head on that one.


I think it's because your total only adds the first key. Your total should be added (+=) every time a key is passed in it.


Wow! Thank you! The += did the trick. I never would have figured that out or known to come to that conclusion. The instructions are so misleading. Again, thank you.


It looks like you need to add += after the total to get it to work. I have no idea how I would have come close to that conclusion based on the guidance in the instructions, which again are ambiguous!


This is known as a compound operator for accumulating.

a = a + x

is refactored as,

a += x

The addition and re-assignment are done in one operation.


AWESOME!!!! Thank you so much!!!!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.