Help!

I am trying to enter characters (for classroom grades) into my program and convert them to numeric values so I can get gradepoint averages. I can't figure out how to convert A-, A+, B-, B+, etc...
Can someone help?

This is what I have:

class Student:
    def __init__(self, name, hours, qpoints):
        self.name = name
        self.hours = float(hours)
        self.qpoints = float(qpoints)
    def getName(self):
        return self.name
    def getHours(self):
        return self.hours
    def getQpoints(self):
        return self.qpoints
    def gpa(self):
        return self.qpoints/self.hours
    def addLetterGrade(self, letter, credits):  
        self.hours = credits
        self.letter = string.split(letter)
        if letter == "A" or "A-" or "A+": #I Have been trying new
                                                      # ideas here on down 
            ngrade = 4.0
        elif letter == "B" or "B-" or "B+":
            ngrade = 3.0
        elif letter == "C,C-,C+":
            ngrade = 2.0
        elif letter == "D,D-,D+":
            ngrade = 1.0
        else:
            ngrade = 0.0
        self.qpoints = credits * ngrade
        print self.qpoints, self.hours  
 
def main():
    print
    print "This program extends the modified student class program by"
    print "implementing an add letter grade method"
    print                                                                                                                 
 
    stu = Student("stu", 0.0, 0.0)
 
    done = False
    while done == False:
        while True:
            grade_str = raw_input("Enter grade (A, A-, A+, B, B-,                                 "B+,C, C-, C+,"
                                  "D, D-, D+, F or just"
                                  "Enter=exit loop): ").upper()
            print
            if grade_str == "":
                done = True
                break
            if grade_str not in 'A,A-,A+,B,B-,B+,C,C-,C+,D,D-,D+,F':
                print "Error, use A, A-, A+, B, B-, B+, C, C-, C+, D,"
                        " D-,D+, F"
            else:
                break
        while done == False:
            credits_str = raw_input("Enter credits (number of hours): ")
            try:
                credits = float(credits_str)
                break
            except ValueError:
                print "Error, use floating point number"
 
        if done == False:
            stu.addLetterGrade(grade_str, credits) 
 
 
    if stu.getHours() == 0.0:
        print "Zero credit hours recorded"
    else:
        print "Final GPA = ", stu.gpa()
 
 
 
main()

Thanks!!

This if statment logic will not work for you if letter == "A" or "A-" or "A+": . You have to break it up, here is an example:

ps = """
Enter grade letters A through F, you
can also postfix A through D with + or -
(press just Enter to exit the loop when done): """
x = raw_input(ps).upper()

if 'A' in x:
    n = 4
elif 'B' in x:
    n = 3
elif 'C' in x:
    n = 2
elif 'D' in x:
    n = 1
elif 'F' in x:
    n = 0
    
partial = 0.33  # or 0.25 this may vary with the school
if '+' in x:
    n = n + partial
if '-' in x:
    n = n - partial

print n  # test

Thanks!

Thank You all very much for your input. Have a Merry christmas!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.