| 5 | |
| 6 | |
| 7 | def new_game(): |
| 8 | global size |
| 9 | answer = input("Do you want to start a new game of Battleship? ").lower() |
| 10 | |
| 11 | if answer not in ["yes", "y", "no", "n"]: |
| 12 | new_game() |
| 13 | else: |
| 14 | if answer == "yes" or answer == "y": |
| 15 | while True: |
| 16 | try: |
| 17 | size = int( |
| 18 | input( |
| 19 | "Enter a number between 5 and 15.\n\nThis will determine how big the playing board is and how many turns you have to find the Battleship. (5 rows, 5 columns, 5 turns, etc.): " |
| 20 | ) |
| 21 | ) |
| 22 | if size not in range(5, 16): |
| 23 | raise ValueError() |
| 24 | except ValueError: |
| 25 | print("You did not enter a number!") |
| 26 | continue |
| 27 | else: |
| 28 | break |
| 29 | |
| 30 | # Creates the playing board's size, based on the size chosen by the player. |
| 31 | for x in range(0, size): |
| 32 | board.append(["O"] * size) |
| 33 | game() |
| 34 | elif answer == "no" or answer == "n": |
| 35 | print("Thank you for playing!\n") |
| 36 | input("Press the 'Enter' key to exit the game.") |
| 37 | quit() |
| 38 | |
| 39 | |
| 40 | def print_board(board): |