Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
waterlubber
Group Title
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)
 2 years ago
 2 years ago
waterlubber Group Title
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)
 2 years ago
 2 years ago

This Question is Closed

tyteen4a03 Group TitleBest ResponseYou've already chosen the best response.0
What is inside x['homework'/'quizzes'/'tests']?
 2 years ago

rsmith6559 Group TitleBest ResponseYou've already chosen the best response.0
And what is that sum function, it could be causing problems.
 2 years ago

irfans Group TitleBest 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?
 2 years ago

tyteen4a03 Group TitleBest 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)
 2 years ago

Shadowys Group TitleBest 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'.
 2 years ago

peterdb Group TitleBest 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.
 2 years ago

tyteen4a03 Group TitleBest 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.
 2 years ago

Shadowys Group TitleBest ResponseYou've already chosen the best response.0
ah. I got it. sorry about that.
 2 years 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.