7/9 Sending a letter


#1

I'm really confused on this one guys. The error my code gives is: Oops, try again. get_letter_grade(89) returned 'A' instead of 'B' as expected

my code:

lloyd = {
        "name": "Lloyd",
        "homework": [90.0, 97.0, 75.0, 92.0],
        "quizzes": [88.0, 40.0, 94.0],
        "tests": [75.0, 90.0]
    }
    alice = {
        "name": "Alice",
        "homework": [100.0, 92.0, 98.0, 100.0],
        "quizzes": [82.0, 83.0, 91.0],
        "tests": [89.0, 97.0]
    }
    tyler = {
        "name": "Tyler",
        "homework": [0.0, 87.0, 75.0, 22.0],
        "quizzes": [0.0, 75.0, 78.0],
        "tests": [100.0, 100.0]
    }

    # Add your function below!
    def average(numbers):
        total = sum(numbers)
        total = float(total)
        total = total / len(numbers)
        return total

    student = lloyd, alice, tyler

    def get_average(student):
        homework = average(student["homework"])
        quizzes = average(student["quizzes"])
        tests = average(student["tests"])
        return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

    def get_letter_grade(score):
        score = int
        if score >= 90.0:
            return "A"
        elif score >= 80.0:
            return "B"
        elif score >= 70.0:
            return "C"
        elif score >= 60.0:
            return "D"
        else:
            return "F"

    print get_letter_grade(get_average(lloyd))

#2

Try taking out score = int and remove the decimal from if elif statements.


#3

taking out "score = int" instantly solved it. stupid of me! thanks!


#4

that was a nice guess though... excercise said expect integers... haha i did try something like
def get_letter_grade(int(score)):

and it didnt worked either ...i think its not a big deal since we still learning


#5

Just out of curiosity, why is nothing else than "None" appearing in the interpreter, even though we are printing?


#6

You don't need to print the function "get_letter_grade()". Do you need to call this function.
And the argument is just the student, not to call the other function. Try something like this: "get_letter_grade(lloyd)


#7

lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total)
average= total/len(numbers)
return average
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average (student["tests"])
return ((0.1 * homework)+ (0.3 quizzes)+ (0.6tests))
def get_letter_grade(score):
if(score >= 90):
return "A"
elif(score >= 80):
return "B"
elif (score >= 70):
return "C"
elif(score <= 60):
return "D"
else:
return "F"
print get_letter_grade(get_average(lloyd))
i am getting error " Oops, try again. get_letter_grade(69) returned 'F' instead of 'D' as expected."
can anyone help me in this issue?


#8

your last elif statement reads if the score is less than or equal to 60 return "D"


#9

print get_letter_grade and get_average separately


#10

def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
print get_letter_grade(get_average(lloyd))


#11

YEAHHHHHH

all variable here

homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
students = [lloyd, alice, tyler]
score = 0.1*homework + 0.3*quizzes + 0.6*tests

explicit students

lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

first fonction

for student in students:

indented othr fonction

def average(numbers):
    total = sum(numbers)
    total = float(total)
    total = total / len(numbers)
    return total

def get_average(student):
    return score

def get_letter_grade(score):

    if score >= 90 :
        return "A"
    elif score >= 80 :
        return "B"
    elif score >= 70 :
        return "C"
    elif score >= 60 :
        return "D"
    else :
        return "F"

non indented test

print get_letter_grade(get_average(lloyd))


#12

remove the score = int line, you should be fine.


#13

wow, this is my code,haha

lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

Add your function below!

"""def average(numbers):
total= float( sum(numbers))
result=float(total)/len(numbers)
return result
"""

def average(numbers):
total=float(sum(numbers))
result=total/float(len(numbers))
return result

def get_average(student):
homework=average(student["homework"])*0.1
quizzes=average(student["quizzes"])*0.3
tests=average(student["tests"])*0.6
ave=homework+tests+quizzes
return ave

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