May-31-2020, 07:22 AM
You can solve UnboundLocalError by changing the scope of the variable that complains. You need to explicitly declare the global variable. The scope of the variable x in the printx function is global. You can verify the same by printing the value of x in the terminal and it will be 6.