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>Here my previous suggestion with the while loop in the correct place:</p>

<pre><code>import random

yscore = 0
ascore = 0
max_score = 52;

def roll():
    #Notify that the variables you want to use are not defined inside the function
    global yscore
    global ascore
    if deal == "!":
        while (yscore &lt; max_score and ascore &lt; max_score) :
            ydeal = random.randint(1,9)
            adeal = random.randint(1,9)
            print(ydeal)
            print(adeal)
            if ydeal &gt; adeal:
                yscore += 1
            elif ydeal &lt; adeal:
                ascore += 1
            print(yscore, ascore)

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

python