【发布时间】:2022-11-03 14:42:02
【问题描述】:
我已经搜索了网络和这个网站,整天都在胡闹,尝试了 100 种方法来让这个简单的小程序正常工作。我正在练习无休止的 While 循环和字符串用户输入。谁能解释我做错了什么?谢谢!
while True:
print("This is the start.")
answer = input("Would you like to continue? (Y/N) ")
answer = answer.islower()
if answer == "n":
print("Ok thank you and goodbye.")
break
elif answer == "y":
print("Ok, let's start again.")
else:
print("You need to input a 'y' or an 'n'.")
【问题讨论】:
-
错字。你想要
answer = answer.lower()。islower()返回一个布尔值,表示变量是否已经是小写。
标签: python string input while-loop