<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/2?curriculum_id=4f89dab3d788890003000096
<In what way does your code behave incorrectly? Include ALL error messages.>
<What do you expect to happen instead?>
I don’t know why this throws a syntax error. It looks fine to me.
File “python”, line 32
avg = homework + quizzes + tests
^
SyntaxError: invalid syntax
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
def get_average(student):
homework = average(student['homework']) * 0.1
quizzes = average(student['quizzes']) * 0.3
tests = average(student['tests'] * 0.6
avg = homework + quizzes + tests
return avg
Hi this part
tests = average(student['tests'] * 0.6
it’s missing the closing )
of the average()
Thanks, can’t believe I missed that.
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”])
avg = (homework*(10/100))+(quizzes*(30/100))+(tests*(60/100))
return avg
get_average(alice)
Why dosen’t this work?
HI its because the
(10/100) , (30/100), (60/100)
return a integer which is 0 because the result of the division is a float so if it return a interger in this case it will be 0 since the result is 0,3, 0.1, 0.
6 so change it like that
(0.1) , (0.3), (0.6)
May somebody help me? I totally don’t understand what I made wrong?
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):
#sum of the numbers
total = sum(numbers)
#making the integer a float
total = float(total)
#finding average
total = total / len(numbers)
#storing it until function is called
return total
def get_average(student):
homework = avarage(student[“homework”])
quizzes = avarage(student[“quizzes”])
tests = avarage(student[“tests”])
avg = 0.1 * homework + 0.3 * quizzes + 0.6 * tests
return avg
“Oops, try again. get_average(alice) raised the following error: global name ‘avarage’ is not defined”
Hi this part
homework = avarage(student["homework"])
quizzes = avarage(student["quizzes"])
tests = avarage(student["tests"])
you wrote avarage instead of average
Hello,
Thanks! Yes, I realized and correct it, but it’s still not working.
Then it returns with this: "get_average(alice) raised the following error: unsupported operand type(s) for *: ‘float’ and ‘NoneType’ "
can you post your new code?
here how to formate it
To format code so it’s visible, either wrap it in single backticks for a small amount of code, or triple backticks on an otherwise blank line before and after for a large amount of code.
1 Like
Thanks, it’s done!
Still one letter was mistaken.
Thnak you!
1 Like
def get_average(student):
homework = average(student[“homework”])
quizzes = average(student[“quizzes”]
tests = average(student[“tests”])
get_avetage = (0.1 * homework + 0.3 * quizzes + 0.6 * tests) / 3
return get_average
What’s wrong with my code?
File “python”, line 31
tests = average(student[“tests”])
^
SyntaxError: invalid syntax
HI this part
quizzes = average(student["quizzes"]
its missing the closing ) of the average()
I’m stuck on this as well. I’m getting an error that reads:
“Oops, try again. get_average(alice) raised the following error: ‘float’ object is not iterable”
I gather there’s an issue with the float being there in total but why would this be a problem?
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))
return total/len(numbers)
def get_average(student):
homework = average(student[“homework”]) * .10
quizzes = average(student[“quizzes”]) * .30
tests = average(student[“tests”]) * .60
return sum(homework + quizzes + tests)
HI the sum() function take a list like that
num = [1,2]
print sum(num)
#Output
3
and you are doing somethig like that
num1 = 1
num2 = 2
print sum(num1, num2)
Output
Traceback (most recent call last):
File "python", line 3, in <module>
TypeError: 'int' object is not iterable
so here
return sum(homework + quizzes + tests)
you should change it
Hint
return sum([#here add the homework + quizzes + tests ])