Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

waterlubber

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

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

  2. rsmith6559
    • 2 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
    • 2 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
    • 2 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
    • 2 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
    • 2 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
    • 2 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
    • 2 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

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.