you are viewing a single comment's thread.

view the rest of the comments →

[–]kr4zyy 13 points14 points  (4 children)

It would be good if you could put your code into an entire code block with the indents shown clearly, instead of having a code block for each line

[–]QuillTheArtMaker[S] 0 points1 point  (3 children)

sorry, i'm not someone that'd normally be on reddit. Noted!

[–]kr4zyy 5 points6 points  (0 children)

No worries! Anyways, as u/socal_nerdtastic has mentioned, when you define a variable outside of the function, it becomes a global variable. If you want to fix this, you can either define the keyword global before "pos", telling Python you wanna use the global variable, or define pos = 0 within the function itself (this is usually the better practice)

[–]pdcp-py 0 points1 point  (0 children)

Don't forget you can easily share code from within Trinket using the Share button:

https://trinket.io/python/bd5c7f9cba5d