14. Test Run - Blank Entry



When testing the code, I get an error if I try to leave one of the inputs blank:

Traceback (most recent call last):
File "python", line 22, in
ValueError: invalid literal for int() with base 10: ''

Is there a simple if statement to test if the raw input is blank and return a new message?

guess_r = raw_input("Guess Row:")
if guess_r == "":
  print "Blank"
  guess_row = int(guess_r)

Update: I started playing around with the above line and it correctly identified if the input is blank. I guess I would need to loop back to the input some how.


ideally, you would do this:

while True:
        guess_r = int(raw_input("Guess Row:"))
    except ValueError:
        print "Not a integer"

try except allows you to handle errors


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.