Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Help me! Codecademy error with this code:
def getAverage(x):
h = sum(x['homework']) * .1
q = sum(x['quizzes']) * .3
t = sum(x['tests']) * .6
return h + q + t
(Just weight and see)
 one year ago
 one year ago
Help me! Codecademy error with this code: def getAverage(x): h = sum(x['homework']) * .1 q = sum(x['quizzes']) * .3 t = sum(x['tests']) * .6 return h + q + t (Just weight and see)
 one year ago
 one year ago

This Question is Closed

tyteen4a03Best ResponseYou've already chosen the best response.0
What is inside x['homework'/'quizzes'/'tests']?
 one year ago

rsmith6559Best ResponseYou've already chosen the best response.0
And what is that sum function, it could be causing problems.
 one year ago

irfansBest ResponseYou've already chosen the best response.0
Is this a fragment of code or whole code. You have a function but where is rest of the code?
 one year ago

tyteen4a03Best ResponseYou've already chosen the best response.0
The sum() function is a builtin function that takes the sum of an iterable (list, iterator, set, generator, etc)
 one year ago

ShadowysBest ResponseYou've already chosen the best response.0
you forgot to put the dot after x, e.g.x.['homework'](the dot means 'the method/element of something'.
 one year ago

peterdbBest ResponseYou've already chosen the best response.0
If you copied and pasted the code then the "t = sum" line looks misaligned from the lines above it.
 one year ago

tyteen4a03Best ResponseYou've already chosen the best response.0
@Shadowys Incorrect. the dot syntax is used to reference an object's methods, not used to access array elements. The syntax of this function is correct.
 one year ago

ShadowysBest ResponseYou've already chosen the best response.0
ah. I got it. sorry about that.
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.