0

我有这个项目,但我不知道如何检查 x 或 o 是否获胜。此外,由于我附加列表的方式,我不知道如何使用 count 函数检查 x 或 o 是否播放了太多次。你会在我的代码中明白这一点:

if user_option == 0:
        print("option 0")
        print ("For each row, start with x. Enter a combination of x's "\
            "and o's up to three characters. For a blank space," \
            "enter a period '.'.")
        msg = [ "top row", "middle row", "bottom row"]
        col_size = 3
        row_size = 3
        ttt = list()
        for n in range(col_size):
            rows = input(msg[n]+ ":")
            ttt.append(rows)
        print(ttt)
        valid_symbols = ['x','X','o','O','.']
        done= False
        for i in ttt:
            if len(i) < 3:
                print("invalid board - too few symbols")
                break
            elif len(i) > 3:
                print("invalid board - too many symbols")
                break
            for x in i:
                if x not in valid_symbols:
                    print("invalid board - invalid symbol "\
                        + x )
                    done = True
                    break
                else:
                    continue
            for o in i:
                if o not in valid_symbols:
                    print("invalid board - invalid symbol "\
                        + o)
                    done = True
                    break
                else:
                    break 
4

0 回答 0