【发布时间】:2014-10-16 10:32:19
【问题描述】:
我正在尝试使用 raw_input() 从用户那里获取字符输入,看看这是 Y 还是 N。应该完成这项工作的代码如下:
#
# Things I have done before
#
c = ""
while c.capitalize() != "Y" or c.capitalize() != "N":
c = raw_input("\n\n If you wish to continue, press Y (or N to terminate) ")
if c.capitalize() == "N":
system.exit("Stopped script......check your files if necessary\n\n");
else:
#Other things to do
目前,即使按Y或N,我也会反复收到提示。不知道这是什么问题。我尝试使用 input() 而不是 raw_input() 但我认为我使用的是旧版本的 python (2x),这就是为什么需要使用 raw_input。
感谢任何帮助。
【问题讨论】:
-
while c.capitalize()!= 'N': -
这真的是我的疯狂和愚蠢......从一种语言切换到另一种语言让我有点小气......暂时...... :(
标签: python input while-loop