Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 27 Online
OpenStudy (anonymous):

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/

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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!

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!