elif statement not working as expected
<p>I'm trying to look through multiple sources to see which one has a specific entry.</p>

<p>My input looks like:</p>

<pre><code>json_str2 = urllib2.urlopen(URL2).read()
u = json.loads(json_str2)
#load all five results
One = u['flightStatuses'][0]
Two = u['flightStatuses'][1]
Three = u['flightStatuses'][2]
Four = u['flightStatuses'][3]
Five = u['flightStatuses'][4]
</code></pre>

<p>My <code>if</code> statement works correctly and I get the correct result:</p>

<pre><code>if One['flightNumber'] == str(FlEnd):
    fnumber = One['flightId']
    print fnumber
</code></pre>

<p>But when I add the <code>elif:</code> the answer is wrong (nothing) even when the first statement is <code>True</code>.</p>

<p>I don't understand why the <code>elif</code> doesn't work?</p>

<pre><code># if statement checks each result to define flightId, needed for tracking.
if One['flightNumber'] == str(FlEnd):
    fnumber = One['flightId']
elif Two['flightNumber'] == str(FlEnd):
    fnumber = Two['flightId']
print fnumber
</code></pre>

<p>You should write this as a loop over the five flight statuses instead of using five variables and five conditions.</p>

<pre><code>results = json.loads(urllib2.urlopen(URL2).read())['flightStstuses']
for result in results:
    if result['flightNumber'] == str(FlEnd):
        fnumber = result['flightId']
        break
else:
    fnumber = None
print fnumber
</code></pre>

python if-statement comparison