【发布时间】:2015-04-07 11:58:45
【问题描述】:
我正在尝试使用 while 循环 getInput(myList) 更改此嵌套列表游戏板中的多个元素,但是当我输入“q”时循环不会停止
def firstBoard():
rows = int(input("Please enter the number of rows: "))
col = int(input("Please enter the number of columns: "))
myList = [[0]*col for i in range(rows)]
return myList
def getInput(myList):
rows = input("Enter the row or 'q': ")
col = input("enter the column: ")
while rows != "q":
rows = input("Enter the row or 'q': ")
col = input("Enter the column: ")
myList[int(rows)-1][int(col)-1] = "X"
return myList
def printBoard(myList):
for n in myList:
for s in n:
print(s, end= " ")
def main():
myList = firstBoard()
myList = getInput(myList)
printBoard(myList)
main()
例如,如果我希望我的输出结果如下:
X 0 0 0 0
0 X 0 0 0
0 0 X 0 0
0 0 0 0 0
0 0 0 0 0
【问题讨论】:
标签: python-3.x while-loop