variables not defined in if statements for change counting program
<p>I'm making a change counter and I'm having trouble printing the percentage for a grade, whenever I run the program I can enter as many inputs as I want, however, when I type done, which is supposed to terminate the program and leave the user with the percentage and letter grade, it just ends the program. If I could get any advice it would be greatly appreciated.
here's my code:</p>

<pre><code>grade=""
total=0
count=1
scores=''

while scores != 'done':
    scores=input("Enter Homework score: ")
    if scores.isdigit():
        numeric=int(scores)
        percentage=(numeric*10/count)
    elif percentage &gt;= 92 and percentage &lt; 100:
        letter = 'A'
    elif percentage &gt;= 87 and percentage &lt; 92:
        letter = 'B+'
    elif percentage &gt;= 80 and percentage &lt; 87:
        letter = 'B'
    elif percentage &gt;=77 and percentage &lt; 80:
        letter = 'C+'
    elif percentage &gt;=70 and percentage &lt; 77:
        letter = 'C'
    elif percentage &gt;= 67 and percentage &lt; 70:
        letter = 'D+'
    elif percentage &gt;= 60 and percentage &lt; 67:
        letter = 'D'
    elif percentage &lt; 60 and percentage &gt;= 0:
        letter= 'F'
    elif (numeric) &lt; 0:
        print("Score must be between 0 and 10")
    elif (numeric) &gt; 10:
        print("Score must be between 0 and 10")
    elif (scores)== 'done':
         print(percentage,"% and you got an, ",letter)
</code></pre>

<p>Your conditional logic is flawed. You are never assessing the grade (<code>letter</code>) if the <code>score.isdigit()</code>:</p>

<pre><code>while scores != 'done':
    scores=input("Enter Homework score: ")
    if scores.isdigit():
        numeric=int(scores)
        percentage=(numeric*10/count)
        if percentage &gt;= 92 and percentage &lt; 100:
            letter = 'A'
        elif percentage &gt;= 87 and percentage &lt; 92:
            letter = 'B+'
        ...
</code></pre>

<p>It is often cleaner to jump out of the loop if the initial condition is false, e.g.:</p>

<pre><code>while scores != 'done':
    scores=input("Enter Homework score: ")
    if not scores.isdigit():
        continue

    numeric=int(scores)
    percentage=(numeric*10/count)
    if 92 &lt;= percentage &lt; 100:
        letter = 'A'
    elif 87 &lt;= percentage &lt; 92:
        letter = 'B+'
    ...
</code></pre>

<p>Also in python your shouldn't be afraid of exceptions. A common idiom in python is EAFP (Easier to Ask for Forgiveness than Permission):</p>

<pre><code>while scores != 'done':
    scores=input("Enter Homework score: ")
    try:
        numeric = int(scores)
    except ValueError:
        continue
</code></pre>

<p>You might also want to think about better ways of doing the large grade <code>if</code> <code>elif</code> <code>elif</code> ... block. E.g. an alternative approach would be define a dictionary of the grades:</p>

<pre><code>grades = {'A': (92, 100), 'B+': (87, 92)} # Etc..
score = 93
_, letter = max((low &lt;= score &lt; high, letter) for letter, (low, high) in grades.items())
print(letter) # 'A'
</code></pre>

python