编写一个接受输入并反转用户输出的程序?
程序重复执行,当用户输入文本行的“Done”、“done”或“d”时程序结束。
例如:如果输入是:
Hello there
Hey
done
那么输出是:
ereht olleH
yeH
我已经编写了大部分程序,但我正在努力定义 user_string
。
user_string = str(input())
while True:
user_string = str(input())
if user_string == 'Done' or mystring == 'done' or mystring == 'd':
break
print(user_string[::-1])
The program repeats, ending when the user enters "Done", "done", or "d" for the line of text.
Ex: If the input is:
Hello there
Hey
done
then the output is:
ereht olleH
yeH
I have written most the program but I'm struggling with defining the user_string
.
user_string = str(input())
while True:
user_string = str(input())
if user_string == 'Done' or mystring == 'done' or mystring == 'd':
break
print(user_string[::-1])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定
mystring
应该做什么,因为它突然出现,没有任何明确的目的。但是,根据给定的代码进行判断,您应该尝试:
Not sure what
mystring
is supposed to do, as it just suddenly appears without any clear purpose.However making judgement from the given code you should try:
在 if 条件下,您必须将 user_string 与 Done、d 或 done 进行比较,而不是与变量
mystring
进行比较。应该是这样的In you if condition you have to compare user_string with Done, d or done instead of the variable
mystring
. Here is how it should be