Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python The Lambda Lambada Reduce

Calvin Hoag
Calvin Hoag
8,515 Points

Unhelpful error feedback

Challenge Task 1 of 4 says "Let's start by writing a function named product_sales that takes a single two-member tuple made up of a price and a number of units sold. product_sales should return the product of the price and the number of units." - I don't know if I have the answer or not but neither the video, or the error feedback is being helpful. I don't understand where the error "Bummer! product_sales threw an exception when given the argument (10.5, 2)"

prices.py
prices = [
    (6.99, 5),
    (2.94, 15),
    (156.99, 2),
    (99.99, 4),
    (1.82, 102)
]

def product_sales(x, y):
    return x * y

1 Answer

Steven Parker
Steven Parker
216,017 Points

Those "bummer" messages aren't always helpful.

:point_right: So here's some hints:

  • the challenge says the function should take a single argument (yours currently takes two).
  • the argument will be a two-member tuple, so you will subscript it to get the 2 values
  • subscripting is done with brackets ("[]")
  • the indexes of tuple members starts with 0
Calvin Hoag
Calvin Hoag
8,515 Points

Thank you!

def product_sales(x):
    return x[0] * x[1]

Where does it get the argument (10.5, 2)? Is that a built in test happening behind the scenes?