vendredi 20 février 2015

I am struggling with using variables in multiple functions (Variable referenced before assignment!)


Vote count:

0




I'm new to Python and am really liking the code. I am trying to recreate a human population simulator that I saw my friend make in Python. It's REALLY basic and is currently only using 3 variables. Here is my code:



pop = 7000000000
int = 5

#Clear
def cls():
print "\n" * 80

#Main script
def MS():
cls()
print "Population =", pop, "Intelligence =", int
print ""
print "Do You:"
print "A) Increase Population"
print "B) Increase Intelligence"
choice = raw_input("Option:")
if choice == "a" :
print "option a"
elif choice == "A" :
print "option A"
elif choice == "b" :
intel()
elif choice == "B" :
intel![enter image description here][1]()

#Increase Intelligence
def intel():
int = int + 3

MS()


I am learning Python at Code-Academy and am testing my code with their labs using Python version 2.7.2 . Int is my intelligence variable and intel my intelligence increase function name. I want to know why I am getting the "local variable 'int' referenced before assignment" Error when I call the int() function and how to fix it and be able to use my variables in multiple functions. Bear in mind that im only 15, so try and simplify you answer so I understand, because I find a lot of stuff confusing when I searched up solutions. I haven't yet created option A function but it will have similar properties.


Here is a picture of my error:



asked 27 secs ago







I am struggling with using variables in multiple functions (Variable referenced before assignment!)

Aucun commentaire:

Enregistrer un commentaire