Using len()

ctilly at gmail.com ctilly at gmail.com
Sat Mar 11 09:30:57 CET 2006


I have what I think is a very simple question.  I have a Python script
that I found that I want to tweek a little bit.  All I want to do is
add in a validator to make sure a value has been keyed into the imput
box.

The code currently is...
while yourguess != mynum:

	tries = tries + 1
	yourguess = input("Your guess? ")

	if  (yourguess != mynum):

		#blah blah blah

	# end of the if statement
# repeat until user gets it right

But I would like to change it to be something like....

while yourguess != mynum:

	tries = tries + 1
	yourguess = input("Your guess? ")

	if len(yourguess)==0:
		continue

	elif (yourguess != mynum):

		#blah blah blah

	# end of the if statement
# repeat until user gets it right

But this throws the following error and I have no idea why.  Please
enlighten.

My error ==>  len() of unsized object




More information about the Python-list mailing list