hi guys i have two question the first question at line 25 there is a function McDiophantine at line 30 there is a subfunction mcdiophantine which is supposed to print a and d but when the function is called at line 56 it prints d but it doesnot print a the code is don't mind the results of http://dpaste.com/793571/
the traceback tells you what the problem is http://dpaste.com/793660/ that error is described in the Python documentation http://docs.python.org/library/exceptions.html#exceptions.UnboundLocalError
the variable a is not part of the global namespace of mcDiophantine() http://dpaste.com/793668/ http://www.diveintopython.net/html_processing/locals_and_globals.html see namespace here http://docs.python.org/glossary.html http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces http://docs.python.org/reference/executionmodel.html#naming-and-binding
well, you can avoid the error by make sure that all the variables inside the sub-function appear in () OK, try this: Replace `mcDiophantine(x)` by `mcDiophantine(x,a,availablePackets,m)` In addition, you should check your style coding, I think it is a little bit confusing. For example: `a+=m` should be `a += m` Adding some spaces make your function clearer. Good luck!
bwCA variable a is not in the namespace mcDiophantine and what about variable b according to me is not in the namespace so it should not be printed to . is variable b in the namespace and explain
hmmmmm so this - http://dpaste.com/794249/ - is basically the same thing: a nested function using a variable defined in its parent function. and it works. sometimes syntax errors will give you misleading errors. the next step might be to start commenting out stuff and try to get it to something more basic and see if it works. which this - http://dpaste.com/794254/ - does now just start selectively uncommenting till the error comes back. sometimes a missing closing paren will give you an error on a succeeding line maybe there is something amiss with that m variable (just a guess)
Join our real-time social learning platform and learn together with your friends!