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

In python, can you manipulate a variable such as an int inside a function directly without including it as a return value? For example: a = 0 b = 0 def function(x): if x = 0: a += 1 return True else: b += 1 return False print function(0) I had this problem when i tried to track for which part of the code is executed in the example used in this "10. Dictionaries. How to Think Like a Computer Scientist" about Hints using the Fibonacci sequence. Thank you in advance.

OpenStudy (e.mccormick):

Are you familiar with the concept of a global and scope? Two references on the topic: http://www.python-course.eu/python3_global_vs_local_variables.php http://www.diveintopython.net/html_processing/locals_and_globals.html

OpenStudy (anonymous):

a = 0 b = 0 def function(x): global a, b if x == 0: a += 1 return True else: b += 1 return False print function(0) print a, b

OpenStudy (anonymous):

You can use "global" to access global variables. And remember, use "=" to attribution and "==" to compare

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!