I am sorry. I know that this is probably a stupid question. But I am just learning Python and have spent hours trying to figure out what I am doing wrong when trying to declare a global variable in a function. What I am trying to do is modify a variable in the function so that the changed value will be associated with it outside the function. However, when I try to use the variable outside the function it reverts to the initial value set before it was changed, and of course if I don't set an initial value outside the function I get an error saying the variable is not defined. This is a simplified example of what I am trying to understand:
solution = 0 def perform_math(): global solution x = 1 x = 2 solution = x + y return solution print(solution)The program prints 0 instead of 3 when I want it to print 3.