How can I make a while loop only run a limited number of times?
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p>

<p>How can I achieve that?</p>

<pre><code>import random

ydeal = random.randint(1,15)
adeal = random.randint(1,15)

yscore = 0
ascore = 0

def roll():
    if deal == "Deal":
        print(ydeal, adeal)
        if ydeal &gt; adeal:
            yscore + 1
        elif ydeal &lt; adeal:
            ascore + 1
        print(yscore, ascore)

deal = input("Your Turn: ")
roll()
</code></pre>

<p>As a side note: I noticed that when printing <code>yscore</code> and <code>ascore</code> the value does not change during the loop, how can I fix that?</p>

<p>How about this using <code>range</code> as per my comment</p>

<pre><code>import random

def ydeal():
    return random.randint(1,15)
def adeal():
    return random.randint(1,15)

yscore = ascore = draw = 0

def roll():
    global yscore, ascore, draw
    if deal == "Deal":
        for x in range(52):
            yydeal = ydeal()
            aadeal = adeal()
            if yydeal &gt; aadeal:
                yscore += 1
            elif yydeal &lt; aadeal:
                ascore += 1
            else:
                draw += 1
            print("Score:", yscore, ascore, draw)

deal = input("Your Turn: ")
roll()
</code></pre>

<p>Note: using python2.7 you would need to change <code>deal = input("Your Turn: ")</code> to <code>deal = raw_input("Your Turn: ")</code></p>

python