Open in CoCalc
1A_boundary = -1
2B_boundary = -1
3C_boundary = -1
4D_boundary = -1
5
6while D_boundary < 0 or D_boundary > 1:
7    D_boundary = float(raw_input("Enter the minimum percentage required for a 'D' (must be between 0 and 1): "))
8    if (D_boundary < 0) or D_boundary > 1:
9        print 'Sorry, the boundary of', D_boundary, "for a grade of 'D' is invalid.",
10        print "Please try again."
11
12while C_boundary <= D_boundary or C_boundary > 1:
13    prompt = "Enter the minimum percentage required for a 'C' (must be between %f and 1): " % D_boundary
14    C_boundary = float(raw_input(prompt))
15    if (C_boundary <= D_boundary) or C_boundary > 1:
16        print 'Sorry, the boundary of', C_boundary, "for a grade of 'C' is invalid.",
17        print "Please try again."
18
19while B_boundary <= C_boundary or B_boundary > 1:
20    prompt = "Enter the minimum percentage required for a 'B' (must be between %f and 1): " % C_boundary
21    B_boundary = float(raw_input(prompt))
22    if (B_boundary <= C_boundary) or B_boundary > 1:
23        print 'Sorry, the boundary of', B_boundary, "for a grade of 'B' is invalid.",
24        print "Please try again."
25
26while A_boundary <= B_boundary or A_boundary > 1:
27    prompt = "Enter the minimum percentage required for an 'A' (must be between %f and 1): " % B_boundary
28    A_boundary = float(raw_input(prompt))
29    if (A_boundary <= B_boundary) or A_boundary > 1:
30        print 'Sorry, the boundary of', A_boundary, "for a grade of 'A' is invalid.",
31        print "Please try again."
32
33score1 = -1
34while score1 < 0 or score1 > 100:
35    score1 = float(raw_input('Enter the score for exam 1: '))
36    if score1 < 0 or score1 > 100:
37        print 'The score must be between 0 and 100.  Please re-enter'
38
39score2 = -1
40while score2 < 0 or score2 > 100:
41    score2 = float(raw_input('Enter the score for exam 2: '))
42    if score2 < 0 or score2 > 100:
43        print 'The score must be between 0 and 100.  Please re-enter'
44
45score3 = -1
46while score3 < 0 or score3 > 100:
47    score3 = float(raw_input('Enter the score for exam 3: '))
48    if score3 < 0 or score3 > 100:
49        print 'The score must be between 0 and 100.  Please re-enter'
50
51#  Compute the average score and put it into a variable named average_score
52average_score = (score1 + score2 + score3) / 3
53average_score_as_percent = average_score / 100
54
55if average_score_as_percent >= A_boundary:
56    grade = 'A'
57elif average_score_as_percent >= B_boundary:
58    grade = 'B'
59elif average_score_as_percent >= C_boundary:
60    grade = 'C'
61elif average_score_as_percent >= D_boundary:
62    grade = 'D'
63else:
64    grade = 'F'
65
66print "Your average score was", average_score, 'for a grade of', grade
67