Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. '''
  2. Created on Mar 30, 2016
  3.  
  4. @author: lrodriguez
  5. '''
  6.  
  7. from random import randint
  8.  
  9. board = []
  10.  
  11. for x in range(0, 5):
  12. board.append(["O"] * 5)
  13.  
  14. def print_board(board):
  15. for row in board:
  16. print (" ".join(row))
  17.  
  18. print_board(board)
  19. print (board[1][1] == "X")
  20.  
  21. def random_row(board):
  22. return randint(0, len(board) - 1)
  23.  
  24. def random_col(board):
  25. return randint(0, len(board[0]) - 1)
  26.  
  27. #Ship Randomly place on Board
  28. ship_row = random_row(board)
  29. ship_col = random_col(board)
  30.  
  31. #User Guess
  32. guess_row = int(input("Guess Row:"))
  33. guess_col = int(input("Guess Col:"))
  34.  
  35. print (ship_row)
  36. print (ship_col)
  37.  
  38.  
  39. # Write your code below!
  40. Turn = 0
  41.  
  42. while Turn < 3:
  43. if guess_row == ship_row and guess_col == ship_col:
  44. print ("Congratulations! You sank my battleship!")
  45.  
  46. else:
  47. if guess_row not in range(5) or guess_col not in range(5):
  48. print ("Oops, that's not even in the ocean.")
  49.  
  50. elif board[guess_row][guess_col] == "X":
  51. print ("You guessed that one already.")
  52.  
  53. else:
  54. print ("You missed my battleship!")
  55. board[guess_row][guess_col] = "X"
  56. print_board(board)
  57.  
  58. Turn += 1
  59. print ("Turn: " + str(Turn))
  60.  
  61. else:
  62. print ("You have no turns left! You lose.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement