+ 1

Error in the program given in course

This program in the course is giving error: def function(variable): variable += 1 print(variable) function(7) print(variable)

13th Oct 2019, 2:57 PM
Meetu Shringi
Meetu Shringi - avatar
2 odpowiedzi
+ 2
you didn't save the value 7 in any variable so ofc when the scope of the function ends, you can't use the variable which you used in that function.
13th Oct 2019, 3:23 PM
Aaron Stone
Aaron Stone - avatar
+ 1
Okay now. Try it like this. def function(variable): variable += 1 print(variable) variable = 7 function(variable) print(variable)
13th Oct 2019, 3:22 PM
Aaron Stone
Aaron Stone - avatar