One of my students brought this to my attention in his coursework. I've re-written what happened below (but is not the same as the coursework):
def tester(number):
print(number)
numbertotal = num1 + num2
print(numbertotal)
number = input("Input a number: ")
num1 = 2
num2 = 2
tester("number")
Output:
Input a number: 12
number
4
How does the num1 and num2 get up into the function? All I do is pass it the string "number" and it prints that. It does then correctly add 2 and 2, which doesn't make any sense since I don't pass that function either number. I do pass the "number" variable so it does work to pass to but is also just so happens that num1 and num2 are available up there anyway. Does Python now make all variables global now? Even so it shouldn't work... Please help!