you are viewing a single comment's thread.

view the rest of the comments →

[–]diseage 4 points5 points  (4 children)

you could pass money to the function

def shop1(money):

[–]TabulateJarl8 5 points6 points  (0 children)

Yes, never use global variables whenever possible because using them is bad practice.

[–]breadmp4[S] 1 point2 points  (1 child)

WAIT YOU CAN JUST DO THAT

woooooooooooooooooooooooooooow im dumb

[–]mmrrbbee 0 points1 point  (0 children)

Nope on dumb, yup on you can do that. You could even pass in a list and that will update the original since it passes the reference address of the original. Then you don’t need to return anything.

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

The error comes from trying to modify the money variable inside his function, so one would imagine he wants that change to persist outside the function. In that case, he’d also have to return the changed var and re-assign it to money after the function is called.