venture of iit bombay vjti alumni the statement global varname tells python that varname is global variable python stops searching the local namespace for the variable for examplewe define variable money in the global namespace within the function moneywe assign money valuetherefore python assumes moneyas local variable howeverwe accessed the value of the local variable moneybefore setting itso an unboundlocalerror is the result uncommenting the global statement fixes the problem #!/usr/bin/python money def addmoney()uncomment the following line to fix the codeglobal money money money print money