if statement seemingly being ignored in for loop
<p>noobie having trouble with if statements within a for loop </p>

<p>def abilityBuy():</p>

<pre><code>totalPoints = 28 

abilities = {
    "Str":0,
    "Con":0,
    "Dex":0,
    "Int":0,
    "Wis":0,
    "Cha":0 
    }

for i,v in abilities.items():
    print "You have %s points." % totalPoints
    text = "Enter stat for %s: " % i
    stat = raw_input(text)
    if stat == 18: 
        totalPoints = totalPoints - 16 
    elif stat == 17:
            totalPoints = totalPoints - 13
    elif stat == 16:
            totalPoints = totalPoints - 10 
    elif stat == 15:
            totalPoints = totalPoints - 8 
    elif stat == 14:
            totalPoints = totalPoints - 6 
    elif stat == 13:
            totalPoints = totalPoints - 5 
    elif stat == 12:
            totalPoints = totalPoints - 4 
    elif stat == 11:
            totalPoints = totalPoints - 3 
    elif stat == 10:
            totalPoints = totalPoints - 2 
    elif stat == 9:
            totalPoints = totalPoints - 1 
    elif stat == 8:
            totalPoints = totalPoints - 0

    abilities[i] = stat 

print abilities
</code></pre>

<p>abilityBuy()</p>

<p>when ran it suppose to deduce the number of points required for a stat number
example: if stat is equal to 18
reduce totalPoints by 16
this will give the totalpoints the remainder of 12 points but when ran the if statement is seemingly ignored and jumps passed them, adds to the dictionary and loops around and says totalPoints still equal to 28</p>

<p>i don't know if it is indentation  that is causing the issue or something else, also i have other for loops with if statements inside and they work how they are suppose to, yet this one doesn't seem to do what i am asking to</p>

<p>open to any suggestions</p>

<p>thanks</p>

<p>Lyncius </p>

<p>First thing that comes to mind: <code>raw_input()</code> returns a string, but your if statements compare stat to integers so none of them will evaluate to true.
A simple solution is to convert it: <code>int(stat)</code>, but you will want to add a check for when users input non-numbers or values beyond what you test (ie, if a user inputs 19 or 'a').</p>

python