Calculate Final Letter Grade in Python Given 4 Test Scores

Calculate final letter grade in Python given 4 test scores

This:

def ?? (??):
if grade >= 90 and <= 100:
return("You received an A")

elif grade >= 80 and < 90:
return("You received a B")

elif grade >= 70 and < 80:
return("You received a C")

elif grade >= 60 and < 70:
return("You received a D")

else grade < 60:
return("Sorry, you received an F")

Would be:

def gradeScores(FinalGrade):
if FinalGrade >= 90 and FinalGrade <= 100:
return("You received an A")

elif FinalGrade >= 80 and FinalGrade < 90:
return("You received a B")

elif FinalGrade >= 70 and FinalGrade < 80:
return("You received a C")

elif FinalGrade >= 60 and FinalGrade < 70:
return("You received a D")

else:
return("Sorry, you received an F")

And:

print(testOne, testTwo, testThree, finalExam) #will replace with values

Would be:

print(gradeScores(grader(testOne, testTwo, testThree, finalExam))) #will replace with values

Python Letter Grades from Percent Score

As i understood you want it:

def grade(g):
if (g>=90):
return "A"
elif (80<=g<90):
return "B"
elif (70<=g<80):
return "C"
elif (60<=g<70):
return "D"
elif (g<60):
return "F"

g = [87, 92, 100, 54, 72, 84, 81, 74]

for i in range(len(g)):
print(grade((g[i])))

your code is not working because you give list as parametr to a function.

Test Average and Grade - Python

To have it print the letter grade as a user enters a score you can do something like:

#Calculate average
def calc_average(total):
return total / 5

#Grading scale
def determine_score(grade):
if 90 <= grade <= 100:
return 'A'
elif 80 <= grade <= 89:
return 'B'
elif 70 <= grade <= 79:
return 'C'
elif 60 <= grade <= 69:
return 'D'
else:
return 'F'

#Enter 5 test scores
scores = []
for i in range(1, 6):
score = int(input('Enter score {0}: '.format(i)))
print 'That\'s a(n): ' + determine_score(score)
scores.append(score)

total = sum(scores)
avg = calc_average(total)
abc_grade = determine_score(avg)


print('Average grade is: ' + str(avg))
print("That's a(n): " + str(abc_grade))

The letter grade problem was that you were using total which was all the grades added up (hopefully more than 100 if you got at least a 20 on all 5 assignments), so it would always default to the else. You want to use the avg so that it would give you the letter grade corresponding to the average:

abc_grade = determine_score(avg)

You can also omit the grade = total line because you will never use grade after making this change.

Python: How do I add a “Final Grade” converter in my Grading System Calculator

Not really sure what your question is, but here is a more succinct way of getting the letter grade.

>>> scores = [93, 89, 87, 83, 79, 77, 73, 69, 67, 60, 0]
>>> grades = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'F']
>>>
>>> def gradeFor(s):
... grade_scores = zip(scores, grades)
... for score, grade in grade_scores:
... if s >= score:
... return grade

>>> gradeFor(87)
B+
>>> gradeFor(89)
A-
>>> gradeFor(88)
B+
>>> gradeFor(67)
D+
>>> gradeFor(72)
C-
>>> gradeFor(40)
F

Also, you can do

if endProgram.lower() in ('no', 'false'):

Python Program - Use a while loop to calculate the amount of letter grades from user input

You forgot to indent your if statements.

count = 0
gradeA = 0
gradeB = 0
gradeC = 0
gradeD = 0
gradeF = 0

score = int(input("Enter an exam score: "))
while score != -1:
count = count + 1
score = int(input("Enter an exam score: "))

if score >= 90 and score <= 100:
gradeA = gradeA + 1
elif score >= 80 and score <= 89:
gradeB = gradeB + 1
elif score >= 70 and score <= 79:
gradeC = gradeC + 1
elif score >= 60 and score <= 69:
gradeD = gradeD + 1
elif score >= 0 and score <= 59:
gradeF = gradeF + 1

print ("You entered " + str(count) + " exam scores.")
print ("Number of A's = " + str(gradeA))
print ("Number of B's = " + str(gradeB))
print ("Number of C's = " + str(gradeC))
print ("Number of D's = " + str(gradeD))
print ("Number of F's = " + str(gradeF))


Related Topics



Leave a reply



Submit