Log in from a computer to take this course

You'll need to log in from a computer to start Learn Python 2. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

Good job! For now, let’s store coordinates for the ship in the variables ship_row and ship_col. Now you have a hidden battleship in your ocean! Let’s write the code to allow the player to guess where it is.

number = raw_input("Enter a number: ") if int(number) == 0: print "You entered 0"

raw_input asks the user for input and returns it as a string. But we’re going to want to use integers for our guesses! To do this, we’ll wrap the raw_inputs with int() to convert the string to an integer.



Create a new variable called guess_row and set it to int(raw_input("Guess Row: ")).

Create a new variable called guess_col and set it to int(raw_input("Guess Col: ")).

Click Run and then answer the prompts by typing in a number and pressing Enter (or Return on some computers).

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?