重复输入,while 和数组
Repetition of input, with while and arrays
我正在尝试编写一个代码,其中他请求单词的长度(n,n <= 100000),然后是单词本身,直到 n 等于零并结束处理;输出要求反转所有单词。
Entrance Output
7 odacova
avocado esuoh
5
house
0
这是我尝试执行的代码:
numeros = []
word = []
for i in numeros:
while i <= 100000:
n = int(input()) #always ask the length and the word
s = str(input())
numeros.append(n)
word.append(s)
if i == 0:
for w in word:
print(w[::-1]) #output with the words reversed
break
那是因为你的数组 numeros
一开始是空的,所以你的 for 循环甚至不会 运行。我也非常依赖你对你想要什么的描述,因为你的代码与你的描述完全不同。这是应该起作用的东西:
numeros = []
words = []
while True:
n = int(input()) # get number of characters input
if n == 0: # if input is 0, print all reversed words and exit the program
for w in words:
print(w[::-1]) #output with the words reversed
break
if n <= 100000:
s = str(input()) # get word input
numeros.append(n)
words.append(s)
我正在尝试编写一个代码,其中他请求单词的长度(n,n <= 100000),然后是单词本身,直到 n 等于零并结束处理;输出要求反转所有单词。
Entrance Output
7 odacova
avocado esuoh
5
house
0
这是我尝试执行的代码:
numeros = []
word = []
for i in numeros:
while i <= 100000:
n = int(input()) #always ask the length and the word
s = str(input())
numeros.append(n)
word.append(s)
if i == 0:
for w in word:
print(w[::-1]) #output with the words reversed
break
那是因为你的数组 numeros
一开始是空的,所以你的 for 循环甚至不会 运行。我也非常依赖你对你想要什么的描述,因为你的代码与你的描述完全不同。这是应该起作用的东西:
numeros = []
words = []
while True:
n = int(input()) # get number of characters input
if n == 0: # if input is 0, print all reversed words and exit the program
for w in words:
print(w[::-1]) #output with the words reversed
break
if n <= 100000:
s = str(input()) # get word input
numeros.append(n)
words.append(s)