[英]Write a program that takes in a input and reverse the users output?
The program repeats, ending when the user enters "Done", "done", or "d" for the line of text.程序重复,当用户为文本行输入“Done”、“done”或“d”时结束。
Ex: If the input is:例如:如果输入是:
Hello there
Hey
done
then the output is:那么 output 是:
ereht olleH
yeH
I have written most the program but I'm struggling with defining the user_string
.我已经编写了大部分程序,但我正在努力定义
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])
Not sure what mystring
is supposed to do, as it just suddenly appears without any clear purpose.不确定
mystring
应该做什么,因为它突然出现而没有任何明确的目的。
However making judgement from the given code you should try:但是,根据给定的代码做出判断,您应该尝试:
# this line seems redundant, remove it. --> user_string = str(input())
while True:
user_string = input() # str() not needed as input() returns a String by default.
if user_string.lower() in {'done', 'd'}:
break
print(user_string[::-1])
In you if condition you have to compare user_string with Done, d or done instead of the variable mystring
.在您的 if 条件中,您必须将 user_string 与 Done、d 或 done 进行比较,而不是将变量
mystring
进行比较。 Here is how it should be这是应该的样子
#user_string = str(input()) you do not need this
while True:
user_string = str(input())
if user_string == 'Done' or user_string == 'done' or user_string == 'd':
break
print(user_string[::-1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.