How to solve unhandled NameError in Python : <p>So while running the codes on the following error is generated.
It says that the NameError is left unhandled by the user code.</p>

<p>The error:</p>

<pre><code>Traceback (most recent call last):
File "D:\3rd sem\Object Oriented Programming\Lab\VS\PythonApplication1\PythonApplication1\PythonApplication1.py", line 50, in &lt;module&gt;
main()
File "D:\3rd sem\Object Oriented Programming\Lab\VS\PythonApplication1\PythonApplication1\PythonApplication1.py", line 10, in main

grade=str(input("Enter the grade: "))
File "&lt;string&gt;", line 1, in &lt;module&gt;
NameError: name 'a' is not defined
</code></pre>

<p>The code goes like this:</p>

<pre><code>classnum=int(input("Enter the num of classes: "))

def main():
totalcredit=0
totalgpa=0

for i in range(1,classnum+1):
    print "class", i
    credit=int(input("Enter the credit: "))
    grade=str(input("Enter the grade: "))
    totalgpa+=coursePoints(credit,grade)
    totalcredit+=credit

totalcourse=classnum 
semestergpa=totalgpa/totalcredit
print("Semester summary")
print("courses taken: ", classnum)
print("credits taken: ", totalcredit)
print("GPA points: ", totalgpa)
print("Semester GPA: ", semestergpa)

def coursePoints(Credit,Grade):
    if Grade == 'A+' or Grade == 'a+':
        return 4*Credit
    elif Grade == 'A' or Grade == 'a':
        return 4*Credit
    elif Grade == 'A-' or Grade == 'a-':
        return 3.67*Credit
    elif Grade == 'B+' or Grade == 'b+':
        return 3.33*Credit
    elif Grade == 'B' or Grade =='b':
        return 3*Credit
    elif Grade == 'B-' or Grade == 'b-':
        return 2.67*Credit
    elif Grade == 'C+' or Grade == 'c+':
        return 2.33*Credit
    elif Grade == 'C' or Grade == 'c':
        return 2*Credit               
    elif Grade == 'C-' or Grade == 'c-':                        
        return 1.67*Credit                
    elif Grade =='D+' or Grade == 'd+':                      
        return 1.33*Credit                
    elif Grade == 'D' or Grade == 'd':                        
        return 1*Credit                      
    elif Grade == 'D-' or Grade == 'd-':                                
        return 0.33*Credit                     
    else:
        return 0

main()
</code></pre>

<p>Can anyone help for solutions.</p>

<p>Thanks in advance.</p>
