![](/img/trans.png)
[英]Write a program that takes a character as input (string length 1) the output is the next character in the alphabet. If input is 'Z', output is 'A'
[英]Write a program that takes in a input and reverse the users output?
程序重復,當用戶為文本行輸入“Done”、“done”或“d”時結束。
例如:如果輸入是:
Hello there
Hey
done
那么 output 是:
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])
不確定mystring
應該做什么,因為它突然出現而沒有任何明確的目的。
但是,根據給定的代碼做出判斷,您應該嘗試:
# 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])
在您的 if 條件中,您必須將 user_string 與 Done、d 或 done 進行比較,而不是將變量mystring
進行比較。 這是應該的樣子
#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.