I have a completed Battleship! game. I have code to deal with most circumstances, except when a user forgets to enter a row or column. For instances in which the user enters a blank column or row, I would like my program to alert the user and return her to the guess stage. Here is what my code looks like inside of the
for turn in range(4): guess_row = raw_input("Guess Row:") guess_col = raw_input("Guess Col:") if guess_row == "": print "You forgot to guess a row." if guess_col == "": print "You forgot to guess a column." break else: int(guess_row) int(guess_col) if guess_row == ship_row and guess_col == ship_col: print "Congratulations! You sunk my battleship!" break else: if turn == 3: print "Game Over" elif (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): print "Oops, that's not even in the ocean." elif(board[guess_row][guess_col] == "X"): print "You guessed that one already." else: print "You missed my battleship!" board[guess_row][guess_col] = "X" print "Turn", turn+1 print_board(board)
As you can see, I removed the
int() wrapper on both
raw_input so that the first two
if statements can properly check for a blank response. After that, I run into trouble. If the response is not blank, I need to convert the input to an integer so that the rest of my program will function. I'm a bit puzzled as to how to accomplish this. Any suggestions?