2017-11-28 8 views
0

私は一見些細な問題にしばらく拘ります。最後のエリフチャンクだけが実行されます

私は、ユーザにraw_inputを入力させ、入力された入力に基づいて変数を割り当てる条件付きループを持っています。ここで

は私の説明を明確にするためのコードです:

location = raw_input("Where are you located? : ") 
#print (location) 

if location == "London": 
    recreationList = londonRec 
    businessList = londonBus 

elif location == "California": 
    recreationList = caliRec 
    businessList = caliBus 

elif location == "Mumbai": 
    recreationList = mumbaiRec 
    businessList = mumbaiBus 

....code to be executed based on location 

私が直面する問題をあるだけで、以下のコードが実行されることをするときraw_input()としてI入力ムンバイ、それは"Where are you located?"まで戻り、他のすべての時間。

私はこれが本当にシンプルなものだと感じています。私は完全に見落とされています。

ありがとうございました

+3

インデントが間違っている場合はもちろん、この動作を引き起こす可能性のある現在のコードには何もありません。 https://stackoverflow.com/help/mcve – Shadow

+2

'' mumbai "==" Mumbai "#False' –

+0

[mcve] –

答えて

2

値を割り当てる前に変数を作成する必要があると思います。これはあなたの問題を解決するかもしれませんが、わかりません。スコープの詳細については、linkを参照してください。また、インデントが正しくありません。

location = raw_input("Where are you located? : ") 
#print (location) 

recreationList = None 
businessList = None 

if location == "London": 
    recreationList = londonRec 
    businessList = londonBus 

elif location == "California": 
    recreationList = caliRec 
    businessList = caliBus 

elif location == "Mumbai": 
    recreationList = mumbaiRec 
    businessList = mumbaiBus 

....code to be executed based on location 
0

変数が正しく定義されていないため、コードが機能しません。 Pythonは他の変数をその変数に設定するだけで変数を作成しないため、事前定義する必要があります。

関連する問題