In: Computer Science
#Python program using loop instead of numpy or pandas.
Write a function to enter n student scores from 0 to 100 to
represent student score,
Count how many A (100 - 90), B(89-80), C(79-70), D(69-60),
F(<60)
We will use numpy array OR pandas later for this problem, for now
use loop
Invoke the function with 10 student scores, show the result as follow:
Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student score: 77 Enter a student score: 66 Enter a student score: 55 Enter a student score: 90 Enter a student score: 80 Enter a student score: 70 Enter a student score: 60 Enter a student score: 50 Grades : As : 2 Bs : 2 Cs : 2 Ds : 2 Fs : 2
CODE -
# Initializing the number of student scores to 10
n = 10
# Initializing the no. of students in each category of grade to 0
count_A = 0
count_B = 0
count_C = 0
count_D = 0
count_F = 0
print("Enter 10 scores")
# Iterating for no. of scores times
for i in range(n):
# Asking user for score
score = int(input("Enter a student score: "))
# Increasing the count of student in a grade category if score lies in that grade
if score>=90 and score<=100:
count_A += 1
if score>=80 and score<=89:
count_B += 1
if score>=70 and score<=79:
count_C += 1
if score>=60 and score<=69:
count_D += 1
if score<60:
count_F += 1
# Displaying the result
print("\nGrades:")
print("As:", count_A)
print("Bs:", count_B)
print("Cs:", count_C)
print("Ds:", count_D)
print("Fs:", count_F)
SCREENSHOTS -
CODE -
OUTPUT -
If you have any doubt regarding the solution, then do
comment.
Do upvote.