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!!