I've noticed a very curious phenomenon here. I've instantiated a global variable (usrPIN
), and I'm comparing it to a local variable (c
). When I input a value (in this case, four zeros), the value is chopped off, creating a string that is one character long. Why?
usrPIN
...
def login():
global usrPIN
...
c = str(input("Enter PIN"))
print usrPIN
print str(c)
if usrPIN == c:
mainMenu()
else:
print "Incorrect PIN"
login()
What on earth is going on?
In Python 2.x input()
does automatic evaluation. What this means is when I do:
input(0.2757)
Python evaluates that to be a float. Similarly, in your case 0000
is evaluated as an integer and since four zeros is the same as one zero, it chops those away. In Python 2.x it's generally always recommended to use raw_input()
for safety.
Note: raw_input()
in Python 2.x always returns a string.