A program deals with grades of a group of students. It first asks a user to ente
ID: 3625726 • Letter: A
Question
A program deals with grades of a group of students. It first asks a user to enter a positiveinteger number to indicate the size of the group. Then it asks the user to enter scores of these
students. Based on standard grading scheme (90.0 and above is ‘A’, 80 to less than 90 is ‘B’, 70
to less than 80 is ‘C’, 60 to less than 70 is ‘D’ and less than 60 is ‘F’), the program assigns letter
grades to the students. Then it displays how many students got ‘A’, how many got ‘B’ how many
got ‘C’, and so on. Write this program.
Explanation / Answer
def main():
groupSize = int(raw_input("Enter the number of students: "))
gradeCount = {"A":0,"B":0,"C":0,"D":0,"E":0}
for student in range(groupSize):
score = float(raw_input("Enter score for student %d: "%student))
if score >= 90:
gradeCount["A"] += 1
elif score >= 80:
gradeCount["B"] += 1
elif score >= 70:
gradeCount["C"] += 1
elif score >= 60:
gradeCount["D"] += 1
else:
gradeCount["E"] += 1
for k,v in gradeCount.items():
print "Number of students that got a grade of %s: %d"%(k,v)
if __name__=="__main__":
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.