Extra Credit - Infinite While Loop


#1

https://www.codecademy.com/en/courses/python-beginner-en-4XuFm/2/5?curriculum_id=4f89dab3d788890003000096

For this program, I am creating a two-player Battleship! game. At the end of the program, I ask the user to put in coordinates for his ship. Then, I ask the user for other coordinates if the coordinates are not in the ocean.

When I run the program, I expected that the program would exit once the user puts in coordinates like (3, 4), but the code keeps asking the user for other coordinates. Is it a problem with my code?


my_ship_x = raw_input("X-cordinate for your ship: ")
my_ship_y = raw_input("Y-cordinate for your ship: ")
print my_ship_x, ", ", my_ship_y
print len(my_board)
print len(my_board[0])

while (my_ship_y < 0 or my_ship_y >= len(my_board) or \
my_ship_x < 0 or my_ship_x >= len(my_board)):



#2

my_ship_x and my_ship_y are strings, string and integer (which you use in while loop) comparison sucks, it just doesn’t work.


#3

Thank you, stetim94!


#4