7/9 Student Becomes the Teacher


#1

I need help. After looking at others I think I have the right code but I can't pass. Any help you be great:

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 = 0
total = sum(numbers)
total = float(total)
return total/len(numbers)

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 = float(score)
if (score >=90):
return "A"
elif (score is >=80):
return "B"
elif score is >=70:
return "C"
elif (score is >=60):
return "D"
else: return "F"

print get_letter_grade(get_average(llyod))

The error I get is the following:

File "python", line 37
elif (score is >=80):
^
SyntaxError: invalid syntax


#2

delete all the 'is'
it would be okay then


#3

def average(numbers):
    total = sum(numbers)
    float(total)
    average = total / float(len(numbers))
    return average
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return  homework * 0.1 + quizzes * 0.3 + tests * 0.6
    
def get_letter_grade(score):
    score = float(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))

#4

I finally figured out how to post the code without losing the formatting! Check my code out and see if it helps! But just by looking at your code at first glance, there is no need to put () around if and elif funtions, and no need for the word is in there either.


#5

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"

It worked, but when I try to test

print get_letter_grade(get_average(llyod))

The follow message came up

Traceback (most recent call last):
File "python", line 46, in
NameError: name 'llyod' is not defined


#6

Never mind, i figure it out, There was a "tab" missing :grin:


#7

Oops, try again. Did you give lloyd the homework key? I'm getting this error message and i don't even know why. This is the code i have so far.
lloyd = {
"name": "Lloyd"
"homework"
"quizzes"
"tests"
}
alice = {
"name": "Alice"
"homework"
"quizzes"
"tests"
}
tyler = {
"name": "Tyler"
"homework"
"quizzes"
"tests"
}


#8

You don't need the word "is" or the "()" for the elif score >= 80: or any of the other commands


#9

This is very aggravating.... I am getting the the grade returned was B when it should have been A. This is INCORRECT. If you manually calculate the weighted average for lloyd it is 80.55 and therefore a B.

I cannot get past this exercise as your error check logic appears flawed.


#10
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)
    return total / len(numbers)

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

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

Whenever I do the get_letter_grade part, I get the error "Oops, try again. get_letter_grade seems to be missing." Can you help me with this?


#12

tagpro56183 I'm running into the same issue. Have you resolved this?


#13

Deleted and added my >= back for function get_letter_grade and it seems to be working now. Not sure why!

Here's my code in case it helps:

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)
    return total / len(numbers)

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

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))`