Aug-02-2017, 10:45 PM
Each function has it's own scope. The function, which is called in main() could not access to the local variables of main.
The function estim does not see the variable estimation. How could a function evaluate this statement, when estimation is unknown?
In Python you're referencing by name.
The function estim does not see the variable estimation. How could a function evaluate this statement, when estimation is unknown?
estimation = (estimation + number / estimation) / 2This error happens also, when you've assigned a global variable (on module level) and try to assign a new object to this name inside a function. You can use
global
, but you should avoid this. You can assign the object, which is referenced by a global name (variable) to a local name inside your function. Then you can do afterwards a new assignment to the local variable, which don't have an effect on the global variable.In Python you're referencing by name.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!