不可合并的类型str()< INT

时间:2016-03-28 20:59:38

标签: python

我试图在python中对战舰游戏进行编码,我的所有代码似乎都在工作,除了一个特定的行,程序返回时出现以下错误:

"TypeError: unorderable types str() < int()"

当我尝试在我的便携式PyScripter上运行代码时,该程序似乎特别强调了这一行

if (Guess_Board_Row < 0 or Guess_Board_Row > 4) or (Guess_Board_Column < 0 
or Guess_Board_Column > 4):

这是我在其中的代码:

import random


Battleship_Board =[]


for x in range (0,5):
Battleship_Board.append(["O"] * 5)


def print_Battleship_Board(Battleship_Board):
    for row in Battleship_Board:
       print (" ".join(row))


def Random_Board_Row(Battleship_Board):
return random.randint(0, len(Battleship_Board)-1)

def Random_Board_Column(Battleship_Board):
    return random.randint(0, len(Battleship_Board[0])-1)

Battleship_Row = Random_Board_Row(Battleship_Board)
Battleship_Column = Random_Board_Column(Battleship_Board)
print("Row:", Battleship_Row)
print("Column:", Battleship_Column)

for turn in range(4):
Guess_Board_Row = input("Enter a row value")
Guess_Board_Column = input("Enter a column value")

if Guess_Board_Row == Battleship_Row and Guess_Board_Column == Battleship_Column:
    print("You sunk my battleship!")
    break
else:
    if turn == 4:
        Battleship_Board[Guess_Board_Row][Guess_Board_Column] = "X"
        print_Battleship_Board(Battleship_Board)
        print("Game Over")
        print("My Ship was here: [" + str(Battleship_Row) + "][" + str(Battleship_Column) + "]")
    else:
        if (Guess_Board_Row < 0 or Guess_Board_Row > 4) or (Guess_Board_Column < 0 or Guess_Board_Column > 4):
            print("Apologies, that's not on the grid")
        elif(Battleship_Board[Guess_Board_Row][Guess_Board_Column] == "X"):
            print("You already guessed that value")
        else:
            print("You missed my battleship!")
            Battleship_Board[Guess_Board_Row][Guess_Board_Column] = "X"
        print(turn + 1)
        print_Battleship_Board(Battleship_Board)

问题是什么,如何解决?

0 个答案:

没有答案