3
我將如何執行以下操作:強制的raw_input
title_selection = raw_input("Please type in the number of your title and press Enter.\n%s" % (raw_input_string))
if not title:
# repeat raw_input
我將如何執行以下操作:強制的raw_input
title_selection = raw_input("Please type in the number of your title and press Enter.\n%s" % (raw_input_string))
if not title:
# repeat raw_input
這往往與「環式和半」在中間的break
構建完成:
while True:
title_selection = raw_input("Please type in the number of your title and press Enter.\n%s" % (raw_input_string))
if title_selection:
break
print "Sorry, you have to enter something."
這種方法給你一個簡單的機會打印一個信息告訴用戶什麼計劃期望。
title_selection = ''
while not title_selection:
title_selection = raw_input("Please type in the number of your title and press Enter.\n%s" % (raw_input_string))
有必要定義title_selection
爲''
前手,這意味着空(也爲False)。 not
將使False
爲真(否定)。