10. You Win


#1



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


the code is working fine , except that when i type the same row and column , i don't get the message of Congratulations ...


print ship_row
print ship_col

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))


if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"


#2

These are just for debugging, but they should follow the lines where the numbers are generated.


#3

You want Congratulation message?right!
Lets find out when do you get the congratulation message...

Breaking your code.

if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"

to get Congratulations! the if statement condition should return True,
When this condition will be true?

Co-ordinates of ship and the Co-ordinates you input is equal? Right!

How you know the co-ordinates of ship? simply if you print the Co-ordinates of ship!
As you already solved it so I can show you the snippet of solution...

```

ship_row = random_row(board)
ship_col = random_col(board)

You need to call functions and store the values of ship's co-ordinates before you print the Co-ordinates.

You need to put this before you get random guess from user.

It will give you actual co-ordinates of ship

print ship_row
print ship_col

guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))
`


Like this...

I hope it helps!! :slight_smile:
ps: do read the thread and do reply if it solved your problem!! :slight_smile:


#4

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