A_boundary = -1
B_boundary = -1
C_boundary = -1
D_boundary = -1
while D_boundary < 0 or D_boundary > 1:
D_boundary = float(raw_input("Enter the minimum percentage required for a 'D' (must be between 0 and 1): "))
if (D_boundary < 0) or D_boundary > 1:
print 'Sorry, the boundary of', D_boundary, "for a grade of 'D' is invalid.",
print "Please try again."
while C_boundary <= D_boundary or C_boundary > 1:
prompt = "Enter the minimum percentage required for a 'C' (must be between %f and 1): " % D_boundary
C_boundary = float(raw_input(prompt))
if (C_boundary <= D_boundary) or C_boundary > 1:
print 'Sorry, the boundary of', C_boundary, "for a grade of 'C' is invalid.",
print "Please try again."
while B_boundary <= C_boundary or B_boundary > 1:
prompt = "Enter the minimum percentage required for a 'B' (must be between %f and 1): " % C_boundary
B_boundary = float(raw_input(prompt))
if (B_boundary <= C_boundary) or B_boundary > 1:
print 'Sorry, the boundary of', B_boundary, "for a grade of 'B' is invalid.",
print "Please try again."
while A_boundary <= B_boundary or A_boundary > 1:
prompt = "Enter the minimum percentage required for an 'A' (must be between %f and 1): " % B_boundary
A_boundary = float(raw_input(prompt))
if (A_boundary <= B_boundary) or A_boundary > 1:
print 'Sorry, the boundary of', A_boundary, "for a grade of 'A' is invalid.",
print "Please try again."
score1 = -1
while score1 < 0 or score1 > 100:
score1 = float(raw_input('Enter the score for exam 1: '))
if score1 < 0 or score1 > 100:
print 'The score must be between 0 and 100. Please re-enter'
score2 = -1
while score2 < 0 or score2 > 100:
score2 = float(raw_input('Enter the score for exam 2: '))
if score2 < 0 or score2 > 100:
print 'The score must be between 0 and 100. Please re-enter'
score3 = -1
while score3 < 0 or score3 > 100:
score3 = float(raw_input('Enter the score for exam 3: '))
if score3 < 0 or score3 > 100:
print 'The score must be between 0 and 100. Please re-enter'
average_score = (score1 + score2 + score3) / 3
average_score_as_percent = average_score / 100
if average_score_as_percent >= A_boundary:
grade = 'A'
elif average_score_as_percent >= B_boundary:
grade = 'B'
elif average_score_as_percent >= C_boundary:
grade = 'C'
elif average_score_as_percent >= D_boundary:
grade = 'D'
else:
grade = 'F'
print "Your average score was", average_score, 'for a grade of', grade