2024-06-16 10:13:34 发布
网友
我正试图编写一个程序,打印一个从用户输入中提取的反向字符串,并不断重复,直到输入“Quit”、“Quit”或“q”。你知道吗
例如:如果输入是:
Line One Line Two quit
则输出为:
enO eniL owT eniL
当前,循环不会终止,也不会移动到第二行输入。它继续打印第一行的背面。你知道吗
s = input() while s != "quit": print (s[::-1])
s = input() quit_txt = ['Quit', 'quit', 'QUIT', 'q'] while s not in quit_txt: print(s[::-1]) s = input()
每次通过循环时都需要输入一个新字符串。您仅有的代码只输入一个字符串,然后退出或永远打印其反向:
s = input() while s not in {"quit", "Quit", "q"}: print (s[::-1])
您可以将其更改为:
s = input() while s != "quit": print (s[::-1]) s = input()
这将获得一个新的字符串每次通过。你知道吗
每次通过循环时都需要输入一个新字符串。您仅有的代码只输入一个字符串,然后退出或永远打印其反向:
您可以将其更改为:
这将获得一个新的字符串每次通过。你知道吗
相关问题 更多 >
编程相关推荐