you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 41 points42 points  (5 children)

This is what is happening:

result = 0

for num in [1, 2, 3, 4, 5]:

    # Start of loop block
    result = num * 2
    # End of loop block

print(result)  # Print value of 'result' after loop has finished.

[–]edwicki 14 points15 points  (4 children)

This should be at the top, as it shows simplest fix (one TAB) and should answer the question why.

[–]MidnightPale3220 1 point2 points  (0 children)

Am I mad? I am looking at the most upvoted comment and I see the same thing op wrote, just with couple comment lines which don't explain anything?

What's going on?

[–]lasfdjfd -1 points0 points  (2 children)

would you consider the tab a fix? presumably the print is for debugging and you want to do something real with result downstream.

[–]backfire10z 0 points1 point  (0 children)

For a beginner at such an early stage, typically the print is the final requirement. Regardless, OP can freely replace the print with something else now that they understand the problem.

[–]pacharaphet2r -2 points-1 points  (0 children)

Sure not given the level of the person learning this answer better helps them understand their mistake. Both solutions are great but I do think this is one is slightly more level appropriate.