【问题标题】:checking tic tac toe game python检查井字游戏python
【发布时间】:2013-10-13 16:06:25
【问题描述】:

我必须检查完成的井字游戏,并且我必须确保用户输入的每一行都有 3 个符号。我在执行此操作时遇到了问题:

for i in ttt:
            if i < len(3):
                print("invalid board - too few symbols")
            elif i > len(3):
                print("invalid board - too many symbols")
            else:
                continue

ttt 是附加的行。

我在运行它时收到此消息:if i

【问题讨论】:

  • len(i)

标签: if-statement for-loop python-3.x while-loop


【解决方案1】:

函数 len() 不接受 int 类型的值作为参数:参数可以是序列(字符串、元组或列表)或映射(字典)。

在这种情况下,你需要使用 len() 找到 i 的长度,并将其与整数 3 进行比较。

资源:https://docs.python.org/2/library/functions.html#len

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-22
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 2014-04-12
    • 1970-01-01
    相关资源
    最近更新 更多