Need Help in making this function stop repeating itself and just import the five
ID: 3533357 • Letter: N
Question
Need Help in making this function stop repeating itself and just import the five students grade in words.txt accurately in Pyhton. Thanks if can help.
grades ="grades.csv"
def problem4(grades):
f= open(grades,'r')
line = f.readline()
reader = Csv.reader(grades)#choose the states file at this point.
line = line.split(",")
numA = 0
numB = 0
numC = 0
numD = 0
numF = 0
for grade in line:
if grade =="A":
numA = numA
print(str(numA+2) +" students got A")
if grade =="B":
numB = numB
print(str(numB+3) +" students got B")
if grade =="C":
numC = numC
print(str(numC+1) +" student got C")
if grade =="D":
numD = numD
print(str(numD+2) +" students got D")
if grade =="F":
numF = numF
print(str(numF+1) +" student got F")
problem4(grades)
Explanation / Answer
grades ="grades.csv"
def problem4(grades):
f= open(grades,'r')
line = f.readline()
reader = Csv.reader(grades)#choose the states file at this point.
line = line.split(",")
numA = 0
numB = 0
numC = 0
numD = 0
numF = 0
for grade in line:
if grade =="A":
numA = numA +1
if grade =="B":
numB = numB +1
if grade =="C":
numC = numC +1
if grade =="D":
numD = numD +1
if grade =="F":
numF = numF +1
print(str(numA) +" students got A")
print(str(numB) +" students got B")
print(str(numC) +" student got C")
print(str(numD) +" students got D")
print(str(numF) +" student got F")
problem4(grades)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.