Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, November 28, 2012

Codecademy: Sending a Letter


#sample solution



Lloyd = {
    "name":"Lloyd",
    "homework": [90,97,75,92],
    "quizzes": [ 88,40,94],
    "tests": [ 75,90]
    }
Alice = {
    "name":"Alice",
    "homework": [100,92,98,100],
    "quizzes": [82,83,91],
    "tests": [89,97]
    }
Tyler = {
    "name":"Tyler",
    "homework": [0,87,75,22],
    "quizzes": [0,75,78],
    "tests": [100,100]
    }

def average(numList):
sum = 0
for number in numList:
sum += number
return (float(sum)/len(numList))

def getAverage(studDict):
homeworkAve = average(studDict['homework'])
quizAve = average(studDict['quizzes'])
testAve = average(studDict['tests'])
weightedAve = (0.1*homeworkAve)+(0.3*quizAve)+(0.6*testAve)
return weightedAve

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

print get_letter_grade(getAverage(Lloyd))

4 comments:

  1. I've put the exact same answer and it still say: Oops, try again! Make sure average returns a float!

    any solutions?

    ReplyDelete
  2. Thanks. Updated the code to reflect the changes in Codecademy's exercises.

    ReplyDelete
  3. Need to indent the get_letter function:

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

    print get_letter_grade(getAverage(Lloyd))

    ReplyDelete


This is an example of scrolling text using Javascript.

Popular Posts