Python while loop does not work properly
<p>I am using a <code>while</code> loop inside a <code>if</code> / <code>else</code> condition. For some reason under one condition the while loop does not work. The condition is shown in my code below. Under these conditions I would assume that the <code>else</code> condition should be utilized and the <code>weight</code> and the <code>max_speed</code> should be decreased until both <code>while</code> conditions are not valid anymore. What am I doing wrong?</p>

<pre><code>weight = 0
max_speed = 15

if weight == 0 and max_speed &lt;= 10:
    while weight == 0 and max_speed &lt;= 10:
        weight=weight+1
        print(weight)
        print(max_speed)
else:
    while weight != 0 and max_speed &gt; 10:
        weight = weight-1
        max_speed=max_speed-1
        print(weight)
        print(max_speed)
</code></pre>

<p>I think you are confused between <code>or</code> and <code>and</code>.</p>

<p><code>and</code> means that the expression will be <code>True</code> if both condition satisfies. Where <code>or</code> means any condition satisfies.</p>

<p>Now based on your code:</p>

<pre><code>weight = 0
max_speed = 15

if weight == 0 and max_speed &lt;= 10:
    # Goes to else block since max_speed = 15 which is &gt;10
else:
    # This while won't be executed since weight = 0
    while weight != 0 and max_speed &gt; 10:
</code></pre>

python if-statement while-loop