编写一个程序,将一行文本作为输入,并反向输出该行文本。程序重复,当用户输入“Done”、“done”或“d”作为文本行时结束。
例如:如果输入是:
Hello there
Hey
done
那么输出是:
ereht olleH
yeH
我已经有了这样的代码。 我不明白我做错了什么。请帮忙。
word = str(input())
the_no_word = ['Done', 'done', 'd']
while word == "Done" and word == "done" and word == "d":
break
print(word[-1::-1])
这就是我在 Zybooks 中完成的实验室作业并通过了所有测试:
userinput = str(input())
stop = ['Done', 'done', 'd']
while userinput not in stop:
print(userinput[::-1])
userinput = str(input())
确保在 while 循环末尾添加 'userinput = str(input())' ,这样就不会出现无限循环
这可能对你有用:
word = ""
the_no_word = ['Done', 'done', 'd']
while word not in the_no_word:
word = str(input())
print(word[-1::-1])
您需要在每次循环后将用户输入到
word
中,并检查单词是否not在the_no_word
列表中。让我知道这是否是您正在寻找的。
var1 = str(input())
bad_word = ['done', 'd', 'Done']
while var1 not in bad_word:
print(var1[::-1])
var1 = str(input())
刚刚做完题并使用了这个答案。
你可以这样做:
while (word := input()) not in {'Done', 'done', 'd'}:
print(word[::-1])
word = str(input())
the_no_word = ['Done', 'done', 'd']
while word not in the_no_word:
print(word[::-1])
word = str(input())
这应该可以完成工作。
文本 = str(输入()) no_words = ['完成','完成','d']
当文本不是 no_words 时: 打印(文本[-1::-1]) 文本 = str(输入())
这应该对你有用!
word = str(input())
the_no_word = ['Done', 'done', 'd']
while word not in the_no_word:
print(word[-1::-1])
word = str(input())
string = str(input())
no_words = ['Done','done','d']
while string not in no_words:
if string in no_words:
print()
else:
print(string[-1::-1])
string = str(input())