inputs = []
iterations = int(input())
for x in inputs:
currentInput = input()
inputs.append(currentInput)
print(x)
該代碼是行不通的。它應該根據「迭代」製作更多「currentInput」變量。謝謝你,很多,因爲這一直在擾亂我。For循環Python中是行不通的
inputs = []
iterations = int(input())
for x in inputs:
currentInput = input()
inputs.append(currentInput)
print(x)
該代碼是行不通的。它應該根據「迭代」製作更多「currentInput」變量。謝謝你,很多,因爲這一直在擾亂我。For循環Python中是行不通的
您的代碼不工作,因爲這是不對的。
您的循環通過每個元素在列表中inputs
去。但是inputs
是一個空列表;你沒有添加任何東西,所以for循環將不起作用。你必須有這個意思
for x in range(iterations):
currentInput=input()
inputs.append(currentInput)
print(currentInput)
這不是我想要的!我希望它像一個forEach! –
什麼是那麼迭代變量?根據我的理解,您希望在輸入「迭代」中進行多次並將其添加到列表中。 – Natrocks
這是正確的!但是,我想要做的是,然後用x打印。我其實只是擁有它,但隨後我的代碼搞砸了。 –
從你的描述中不清楚你想要這段代碼做什麼。你能詳細說明一下嗎? – jcolemang