我有一个评估输入的函数,我需要继续询问他们的输入并进行评估,直到他们输入一个空行.我怎么设置它?
while input != '': evaluate input
我想过用这样的东西,但它并没有完全奏效.有帮助吗?
有两种方法可以做到这一点.首先是这样的:
while True: # Loop continuously inp = raw_input() # Get the input if inp == "": # If it is a blank line... break # ...break the loop
第二个是这样的:
inp = raw_input() # Get the input while inp != "": # Loop until it is a blank line inp = raw_input() # Get the input again
请注意,如果您使用的是Python 3.x,则需要替换raw_input
为input
.