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
self.hours = credits
self.letter = string.split(letter)
if letter == "A" or "A-" or "A+": #I Have been trying new
# ideas here on down
elif letter == "B" or "B-" or "B+":
elif letter == "C,C-,C+":
elif letter == "D,D-,D+":
else:
print self.qpoints, self.hours

def main():
print
print "This program extends the modified student class program by"
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
done = True
break
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:

if stu.getHours() == 0.0:
print "Zero credit hours recorded"
else:
print "Final GPA = ", stu.gpa()

main()``````

Thanks!!

## All 3 Replies

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.