Jan-27-2023, 12:19 PM
Hello,
indeed true, using global variables and the
Fixing your programm is fairly simple: just pass the
Generally speaking, using global variables is considered bad style, as it makes the state of a program hard to somewhat impossible to trace.
Couple of other comments:
Line 20 is unnecessary and can lead to an recursion error. When a function is finished, it return to the point in the code from where it was called. In you case main calls e.g. left, left may call stop. When stop is finished it returns to left which return to main.
Never use blank
Line 111 will lead to an error, as
Regards, noisefloor
indeed true, using global variables and the
global
keyword is considered bad style and should be prevented. Except that using global variables is in 99% of all cases unnecessary, including your case.Fixing your programm is fairly simple: just pass the
position
as an argument to the function and make the function return the new position, so it is available in your main
function. Passing and returning values to / from functions is one of the basics in Python. In case you don't know I suggest to read the corresponding cheapers in the Python tutorial at docs.python.org .Generally speaking, using global variables is considered bad style, as it makes the state of a program hard to somewhat impossible to trace.
Couple of other comments:
call
doesn't need to be global anyway, as it is used only within main
.Line 20 is unnecessary and can lead to an recursion error. When a function is finished, it return to the point in the code from where it was called. In you case main calls e.g. left, left may call stop. When stop is finished it returns to left which return to main.
Never use blank
try... except
, that's wrong in 99,9% of all cases. Errors need to be caught specifically. Using blank try... except
will catch any error, including programming and syntax error. This can lead to an unexpected behaviour and hard to trace bugs.Line 111 will lead to an error, as
quiet
is not defined.Regards, noisefloor