在python中如何在一个输入函数中有多个参数

2024-09-29 01:26:49 发布

您现在位置:Python中文网/ 问答频道 /正文

此函数向输入函数抛出错误,声明参数无效。。有什么决议吗?

def assignSquareValues():
        square=[[0,0,0],
                [0,0,0],
                [0,0,0]]
        count=0
        try:
            for r in range(3):
                for c in range(3):
                    count+=1
                    print(count)
                    square[r][c]= int(input(("Enter a number(1-9) for square #",(count)+":",sep=''))) #this line throws an error stating that "TypeError: input expected at most 1 arguments, got 2"

        except Exception as err:
            print(err)
            assignSquareValues()

        checkMagicSquare(square)

Tags: 函数in声明forinput参数defcount
1条回答
网友
1楼 · 发布于 2024-09-29 01:26:49

input()需要一个参数-显示文本-因此必须将所有参数连接到一个文本中

也就是说

input("Enter a number(1-9) for square #" + str(count) + ":")

或者

^{pr2}$

相关问题 更多 >