これは何ですか?
def foo():
usr_input = raw_input("Enter you input : a|b|c|d|quit\n")
usr_input_list = usr_input.split('|')
length_of_list = len(usr_input_list)
for usr_input_element in usr_input_list:
if usr_input_element == 'a':
if length_of_list == 1: # Only if there's only an 'a' in list
press_any_key_to_continue()
if usr_input_element == 'c':
if length_of_list > 1: # If there is other things than 'c' in list
press_any_key_to_continue()
if usr_input_element == 'quit':
exit()
def press_any_key_to_continue():
this_variable_will_not_be_used = raw_input("Press any key to continue\n")
print("Now it will continue")
ご入力の場合 "| C | B | |終了| D" それはこの
[ 'A'、 'C'、「Bのように見えるのリストを作成します。 」、 『』、 『終了』、 『D』]
とそのリストの長さは次のようになります。6
そして、forループ、リストを1つずつ移動します。
それとも、この方法でそれを行うことができます。
for usr_input_element in usr_input_list:
if length_of_list == 1: # Only if there's only an 'a' in list
if usr_input_element == 'a':
press_any_key_to_continue()
if usr_input_element == 'c':
press_any_key_to_continue()
if length_of_list > 1: # If there is other things than 'c' in list
if usr_input_element == 'a':
press_any_key_to_continue()
if usr_input_element == 'c':
press_any_key_to_continue()
if usr_input_element == 'quit':
exit()
しかし、その後、あなたがif length_of_list == 1:
と両方の内側にそれらの文が要素ならば、すべて置く必要があることに気づきます。
'uinput'は文字列であり、リストではありません。 – DeepSpace
@ DeepSpaceはい正しい申し訳ありません。もし私がuinput1 = uinput.split( "|")としたら – Ritesh