JYTHON/PYTHON - raw_input losing first character of string -
i reading in name see below, regardless of type in loses first character, example, 'bob' become 'ob'. because of cannot compare user's input searching for, breaking entire program.
def find() : global addressbookall success = false persontofind = str(raw_input("\nenter nickname of person find: ")) x in addressbookall : if(x == persontofind) : success = true printnow("\n%s" %(x)) y in addressbookall[x] : printnow("%s" %(y)) if(success == false) : printnow("\nnot found.")
there few problems code.
first, shouldn't using global variable. make more sense pass address book function. don't worry, reference passed, it's cheap.
second, function names (and other variable names except classes) should lowercase.
third, no need call str()
on raw_input()
returns string.
fourth, use .format()
string syntax instead of %
string formatting.
fifth, x
appears string addressbookall
(that's guess because you're comparing persontofind
it). let's hope addressbookall
dictionary, otherwise addressbookall[x]
fail.
sixth, if single character dropped anywhere, must in printnow()
haven't shown us. there no other place in code happen.
seventh, case matters. true
not same true
. neither success
, success
.
eighth, python not java. if
doesn't need parentheses, example.
Comments
Post a Comment