+ 2

# Multiple inputs problem in code playground đ„ș

When I wrote a program with 2 inputs there is an error that say that I must separate each input with a newline. But it doen't work ! For example the BattleShip code in Python 3 doesn't works in the playground: """Battleship""" from random import randint board = [] count = 0 point = 250 for i in range(5): board.append(["0"]*5) def print_board(board): for row in board: print(" ".join(row)) def rand(board): return randint(1,len(board)-1) print("-"*35) print("Welcome to the Battleship!") print("-"*35) print("Your point:", point) print("-"*35) print_board(board) ship_row = rand(board) ship_column = rand(board) ship1_row = rand(board) ship1_column = rand(board) ship2_row = rand(board) ship2_column = rand(board) while True: if (ship_row == ship1_row and ship_column == ship1_column): ship1_row = rand(board) ship1_column = rand(board) continue elif (ship_row == ship2_row and ship_column == ship2_column): ship2_row = rand(board) ship2_column = rand(board) continue elif (ship1_row == ship2_row and ship1_column == ship2_column): ship2_row = rand(board) ship2_column = rand(board) continue else: print("-" * 35) guess_row = int(input("Type a row: ")) guess_column = int(input("Type a column: ")) if (guess_row == ship_row and guess_column == ship_column) \ or (guess_row == ship1_row and guess_column == ship1_column) \ or (guess_row == ship2_row and guess_column == ship2_column): if board[guess_row - 1][guess_column - 1] == "/": print("-" * 35) print("You have already guessed") print_board(board) print(point) else: print("-" * 35) print("Congratulations! The ship sunk") board[guess_row - 1][guess_column - 1] = "/" print("Point:", point)

1st Apr 2019, 1:07 AM
Pierre Zimmermann