【发布时间】:2016-12-07 20:07:33
【问题描述】:
我需要提示用户输入,直到连续给出 2 个空行,请注意,为清楚起见,输入读取中可能有空行,我需要两个空行背靠背在它中断之前.
到目前为止,我想出了这个:
def gather_intel():
done = False
while done is False:
data = raw_input("Copy and paste the work log: ")
if data is None:
done = True
一旦给出一个空行,这将如何结束,我还尝试向其中添加另一个 while 循环:
def gather_intel():
done = False
while done is False:
data = raw_input("Copy and paste the work log: ")
while data != "" + "\n" + "":
data = raw_input("Copy and paste the work log: ")
if data == "" + "\n" + "":
done = True
然而,这是一个无限循环,永远不会结束。如何提示用户输入,直到有两个空行连续输入?
【问题讨论】:
标签: python python-2.7 input