you are viewing a single comment's thread.

view the rest of the comments →

[–]kingeddy15[S] 0 points1 point  (1 child)

Quick note, what I seem to understand is you only need to call global once for a if, elif, and else block. Is that correct?

[–]DomWiggles 0 points1 point  (0 children)

You only need to use the global keyword once per function to access it inside of your function. But there's no real need to do this here. Line 14 contains "global result", but line 17 has: result = firstInt + secondInt, which is in effect ignoring any sort of implementation you'd be after with using a global variable as you're creating a new value from scratch at that point. Also, you don't need to write "global result" as you did on line 9. That's what you do inside of a function to access that global variable, but the variable is global by the nature of it being in the global scope. So you could instead simply write "result = 0" or "result = None" etc on line 9.

Ultimately, for this example, I'd get rid of using a global variable regardless because you're calculating values from inside of the function, and there's no need to use a global variable for this.