Python random while multiple conditions
<p>Cheers, my problem is that I don't know how to do a while with multiple conditions. I really don't get it why this won't work:</p>

<pre><code>import random

a = 0
b = 0
c = 0

while a &lt; 190 and b &lt; 140 and c &lt; 110: # &lt;-- This condition here
    a = 0
    b = 0
    c = 0

    for i in range(1, 465):
        v = random.randint(1, 3)

        if v == 1:
            a = a + 1
        elif v == 2:
            b = b + 1
        else:
            c = c + 1

    result = ""
    result += "a: " + str(a) + "\n"
    result += "b: " + str(b) + "\n"
    result += "c: " + str(c) + "\n"

    print (result)
</code></pre>

<p>I want to loop this until a is above 190 AND b above 140 AND c above 110 but it stops everytime after the first run.</p>

<p>Can someone help me there?</p>

<p>You could change the logically slightly and use an infinite loop that you then <code>break</code> out of when your conditions are met:</p>

<pre><code>while True:
    # do stuff
    if a &gt;= 190 and b &gt;= 140 and c &gt;=110:
        break
</code></pre>

<p>Your original logic terminated if <em>any</em> of the conditions were met. For example, this loop exits because <code>a</code> is no longer <code>True</code> after the first iteration:</p>

<pre><code>a = True 
b = True
while a and b:
    a = False
</code></pre>

<p>This loop is infinite because <code>b</code> is always <code>True</code>:</p>

<pre><code>a = True
b = True
while a or b:
    a = False
</code></pre>

<p>You could use <code>or</code> instead of <code>and</code> for your initial <code>while</code> loop, but I find the <code>break</code> logic far more intuitive.</p>

python random multiple-conditions