以下をどのように実装しますか:
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
以下をどのように実装しますか:
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
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))
空(Falseでもある)を意味する事前に定義する必要がありますtitle_selection
。''
はTrue (否定) になりますnot
。False
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."
このメソッドを使用すると、プログラムが何を期待しているかをユーザーに伝えるメッセージを簡単に出力できます。