python - Why does my string remove multiple characters? -


i've noticed curious phenomenon here. i've instantiated global variable (usrpin), , i'm comparing local variable (c). when input value (in case, 4 zeros), value chopped off, creating string 1 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() 

enter image description here

what on earth going on?

in python 2.x input() automatic evaluation. means when do:

input(0.2757) 

python evaluates float. similarly, in case 0000 evaluated integer , since 4 zeros same 1 zero, chops away. in python 2.x it's recommended use raw_input() safety.

note: raw_input() in python 2.x returns string.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -