fork(2) download
  1. from random import randint
  2.  
  3. board = []
  4.  
  5. for x 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.  
  23. print ship_row
  24. print ship_col
  25.  
  26. guess_row = int(raw_input("Guess Row:"))
  27. guess_col = int(raw_input("Guess Col:"))
  28.  
  29.  
  30. # Write your code below!
  31.  
  32. if ship_col == guess_row and ship_row == guess_row:
  33. print "Congratulations! You sank my battleship!"
  34. else:
  35. print "You missed my battleship!"
  36. guess_row = "X"
  37. guess_col = "X"
  38. print_board(board)
  39.  
Runtime error #stdin #stdout #stderr 0.02s 10336KB
stdin
Standard input is empty
stdout
O O O O O
O O O O O
O O O O O
O O O O O
O O O O O
2
0
Guess Row:
stderr
Traceback (most recent call last):
  File "prog.py", line 26, in <module>
EOFError: EOF when reading a line