Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from random import randint
  2.  
  3. board = []
  4.  
  5. for i in range(0, 5):
  6. board.append(["O"] * 5)
  7.  
  8. def print_board(board):
  9. for row in board:
  10. print " ".join(row)
  11.  
  12. print_board(board)
  13.  
  14. def random_row(board):
  15. return randint(0, len(board) - 1)
  16.  
  17. def random_col(board):
  18. return randint(0, len(board[0]) - 1)
  19.  
  20. ship_row = random_row(board)
  21. ship_col = random_col(board)
  22. guess_row = int(raw_input("Guess Row:"))
  23. guess_col = int(raw_input("Guess Col:"))
  24.  
  25. print ship_row
  26. print ship_col
  27.  
  28. # Write your code below!
  29. if guess_row == ship_row and guess_col == ship_col:
  30. print "Congratulations! You sank my battleship!"
  31. else:
  32. print "You missed my battleship!"
  33. board[guess_row][guess_col] = "X"
  34. print_board(board)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement