A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years 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)
 2 years 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)

This Question is Closed

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

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

irfans
 2 years ago
Best ResponseYou've already chosen the best response.0Is this a fragment of code or whole code. You have a function but where is rest of the code?

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

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

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

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

Shadowys
 2 years ago
Best ResponseYou've already chosen the best response.0ah. I got it. sorry about that.
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
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.