Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

waterlubber

  • 3 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
  1. tyteen4a03
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What is inside x['homework'/'quizzes'/'tests']?

  2. rsmith6559
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    And what is that sum function, it could be causing problems.

  3. irfans
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Is this a fragment of code or whole code. You have a function but where is rest of the code?

  4. tyteen4a03
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The sum() function is a built-in function that takes the sum of an iterable (list, iterator, set, generator, etc)

  5. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you forgot to put the dot after x, e.g.x.['homework'](the dot means 'the method/element of something'.

  6. peterdb
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If you copied and pasted the code then the "t = sum" line looks misaligned from the lines above it.

  7. tyteen4a03
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 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.

  8. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ah. I got it. sorry about that.

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy