I have most of it but I can't figure out how to word the last part.

def findLargest(L):
    largest = 0
    for x in L:
        if x > largest:
            largest = x
    return largest

def findSmallest(L):
    smallest = 300000000
    for x in L:
        if x < smallest:
            smallest = x
    return smallest

def findAverage(L):
    sum = 0.0
    for x in L:
        sum = sum + x
    return sum/len(L)

def findLetterGrade(score):
    #if (score >= 90) and (score <= 100):
    if score in range(90,101):
        return "A"
    elif score in range(80, 90):
        return "B"
    elif score in range(70, 80):
        return "C"
    elif score in range(60, 70):
        return "D"
    elif score in range(1, 60):
        return "F"
    
def countGrades(L):
    countA = 0
    countB = 0
    countC = 0
    countD = 0
    countF = 0
    for i in L:
        if findLetterGrade(score) == "A":
            countA = countA + 1
        elif findLetterGrade(i) == "B":
            countB = countB + 1
        elif findLetterGrade(i) == "C":
            countC = countC + 1
        elif findLetterGrade(i) == "D":
            countD = countD + 1
        elif findLetterGrade(i) == "F":
            countF = countF + 1
    return [countA,countB,countC,countD,countF]

def computeAnswers(L):
    largest = findLargest(L)
    smallest = findSmallest(L)
    average = findAverage(L)
    gradeCounts = countGrades(totalGrades(L))
    return [gradeCounts[0],gradeCounts[1],gradeCounts[2],gradeCounts[3],
            gradeCounts[4],len(L),average,largest,smallest]

###this is the part I need help with to make the output####
def main():
    ...
    ...
    answers = computeAnswers(Scores)
    print
    print

##The output is SUPPOSED to look like this.

#>>> from Scores import *
#>>> main()
#Enter score (0 to stop): 63
#Enter score (0 to stop): 75
#Enter score (0 to stop): 72
#Enter score (0 to stop): 72
#Enter score (0 to stop): 78
#Enter score (0 to stop): 67
#Enter score (0 to stop): 80
#Enter score (0 to stop): 63
#Enter score (0 to stop): 75
#Enter score (0 to stop): 90
#Enter score (0 to stop): 89
#Enter score (0 to stop): 43
#Enter score (0 to stop): 59
#Enter score (0 to stop): 99
#Enter score (0 to stop): 82
#Enter score (0 to stop): 12
#Enter score (0 to stop): 100
#Enter score (0 to stop): 0
#
#Number of "A" scores = 3
#Number of "B" scores = 3
#Number of "C" scores = 5
#Number of "D" scores = 3
#Number of "F" scores = 3
#-------------------------
#Total Scores = 17

#Average Score = 71.0
#Maximum Score = 100
#Minimum Score = 12

Recommended Answers

All 2 Replies

I guess you can add something like this:
(not sure if you are using py2 or 3, this is 3)

Scores = []
while True:
  a = int(input("Enter score (0 to stop):"))
  if not a:
    break
  Scores.append(a)

I think that should do it.
Didn't test it.

def findLargest(L):
    largest = L[0]
    for x in L[1:]:
        if x > largest:
            largest = x
    return largest

def findSmallest(L):
    smallest = L[0]
    for x in L[1:]:
        if x < smallest:
            smallest = x
    return smallest

def findAverage(L):
    sum = 0.0
    for x in L:
        sum += x
    return sum/len(L)

def findLetterGrade(score):
    #if (score >= 90) and (score <= 100):
    if score in range(90,101):
        return "A"
    elif score in range(80, 90):
        return "B"
    elif score in range(70, 80):
        return "C"
    elif score in range(60, 70):
        return "D"
    elif score in range(1, 60):
        return "F"
    
def countGrades(L):
    countA = 0
    countB = 0
    countC = 0
    countD = 0
    countF = 0
    for i in L:
        if findLetterGrade(score) == "A":
            countA += 1
        elif findLetterGrade(i) == "B":
            countB += 1
        elif findLetterGrade(i) == "C":
            countC += 1
        elif findLetterGrade(i) == "D":
            countD += 1
        elif findLetterGrade(i) == "F":
            countF += 1
    return [countA,countB,countC,countD,countF]

def computeAnswers(L):
    scores = countGrades(L)
    print '\nNumber of "A" scores: %d\nNumber of "B" scores: %d' % (scores[0],scores[1])
    print 'Number of "C" scores: %d\nNumber of "D" scores: %d' % (scores[2],scores[3])
    print 'Number of "F" scores: %d\n------------' % scores[4]
    
    print 'Total scores = ', len(L)
    print 'Average score = ', findAverage(L)
    print '\nMaximum score = ', findLargest(L)
    print 'Minimum score = ', findSmallest(L)
    
            
L = []
score = True
while score:
    try:
        score = int(raw_input("Enter score (0 to stop): "))
    except ValueError:
        continue
        
    if not score:
        break
        
    L.append(score)
    
computeAnswers(L)

There you go ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.