counter not inceasing in python
<p>I have looked at other while loops and am stuck on why this one is not working.</p>

<pre><code>points = int(input('How many points: '))
while True:
    u_cnt, c_cnt = 0, 0
    if u_cnt &lt; points or c_cnt &lt; points:
        if u &lt; c:
            c_cnt += 1
        elif u &gt; c:
            u_cnt += 1
</code></pre>

<p>Is my problems having the <code>c_cnt += 1</code> inside of two if statements?</p>

<p>I have put it outside of the <code>while</code> loop, yet that doesn't increase count either. I have also put the <code>u_cnt = 0</code> and <code>c_cnt = 0</code> on separate lines.</p>

<p>It's not doing an infinite loop, as it should not do. It's just not incrementing.</p>

<p>Thank you</p>

<p>edit:</p>

<pre><code>import random

u_name = input('What is your name? ')
points = int(input('How many points: '))
u_cnt, c_cnt = 0, 0

while True:
    a = ['rock', 'paper', 'scissors']
    comp = random.choice(a)
    print('Pick from:', str(a).strip('[]'))
    user = input()
    u = a.index(user)
    c = a.index(comp)
    line_1 = '{} : {}\t{} : {}'.format(u_name, user, 'Computer', comp)
    line_2 = '{} : {}\t{} : {}\n'.format(u_name, u_cnt, 'Computer', c_cnt)

    if c_cnt &lt; points or u_cnt &lt; points:
        if u &gt; c or u == 0 and c == 2:
            u_cnt += 1
            print(line_1, '\t', u_name, 'wins')
            print(line_2)
        elif u &lt; c or u == 2 and c == 0:
            c_cnt += 1
            print(line_1, '\t', 'Computer wins')
            print(line_2)
        elif u == c:
            print(line_1, '\t', 'Tie')
            print(line_2)
    else:
        break
</code></pre>

<p>so when you run this the first time, you get an answer back like</p>

<pre><code>What is your name? chad
How many points: 3
Pick from: 'rock', 'paper', 'scissors'
rock
chad : rock Computer : scissors      chad wins
chad : 0    Computer : 0

Pick from: 'rock', 'paper', 'scissors'
</code></pre>

<p>how to get the count be 1, 0 on the first iteration through.  that might be a better question.</p>

<p>Writing all this out in hopes that it helps other beginners like me.  If others can explain it better than I do please comment.</p>

<p>So this was a python beginner practice problem from-<br>
<a href="http://openbookproject.net/pybiblio/practice/wilson/rockpaperscissors.php" rel="nofollow">http://openbookproject.net/pybiblio/practice/wilson/rockpaperscissors.php</a><br>
I didn't put the ctrl-d into it though.</p>

<p>I'll make comments on the code that worked how I wanted it to.  That is give the count as each try was went through.</p>

<pre><code>import random

u_name = input('What is your name? ')
points = int(input('How many points to play to? '))
u_cnt, c_cnt = 0, 0
a = ['rock', 'paper', 'scissors']

while u_cnt &lt; points or c_cnt &lt; points:
    comp = random.choice(a)
    print('Pick from:', str(a).strip('[]'))
    user = input()
    u = a.index(user)
    c = a.index(comp)
    line_1 = '{} : {}\t{} : {}'.format(u_name, user, 'Computer', comp)
    if u &gt; c or u == 0 and c == 2:
        u_cnt += 1
        print(line_1, '\t', u_name, 'wins')
    elif u &lt; c or u == 2 and c == 0:
        c_cnt += 1
        print(line_1, '\t', 'Computer wins')
    elif u == c:
        print(line_1, '\t', 'Tie')

    line_2 = '{} : {}\t{} : {}\n'.format(u_name, u_cnt, 'Computer', c_cnt)
    print(line_2)
    if u_cnt == points or c_cnt == points:
        if u_cnt &gt; c_cnt:
            print('\n', u_name.upper(), 'WINS!!!')
        elif u_cnt &lt; c_cnt:
            print('\n', 'COMPUTER WINS!!!')
        print(line_2)
        break

exit()
</code></pre>

<p>To get my count for each attempt I had to put <code>line_2</code> at the end of my first <code>if</code> loop so that it would increment properly.  </p>

<p>If you look at my original post, you will see that I have <code>line_2</code> outside of the first <code>if</code> statement.  This was making it so that it would go through the whole loop and then add the count the next time through, instead of adding it right away.</p>

<p>I put the second <code>if</code> statement in so that it would test the loop and then print who the winner was.</p>

<p>I also learned that I had alot of extra <code>print(line_2)</code> statements in the original post and if I just put the one in I could reduce my typing. (pythonic way?)</p>

<p>I have done this (rock, paper, scissors) on other practice sites and this is the least amount of <code>if, elif</code>'s that I have had to do.</p>

<p>As the people who know what they are doing will tell you, practice code, read code, practice code.</p>

<p>Thank you everyone for your help and tips/tricks.<br>
em</p>

python while-loop