Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRutendo Chaurura
6,809 PointsThis code i not passing
We have a bunch of prices and sales numbers and we need to find out our total earnings.
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.
prices = [
(6.99, 5),
(2.94, 15),
(156.99, 2),
(99.99, 4),
(1.82, 102)
]
def product_sales(price, units):
return price * units
2 Answers
Steven Parker
231,248 PointsThis function takes two individual arguments, but the instructions ask for a function " that takes a single two-member tuple"
So your declaration might look something like:
def product_sales(one_tuple):
And of course, the body would need to be adapted accordingly.
Learn QA
7,207 Pointsdef product_sales(one_tuple): product_sales = 21.0 return product_sales
this code passed but not sure how
Steven Parker
231,248 PointsLooks like you tricked the challenge by guessing the result for the values it tested with.
But a valid solution would use the argument and calculate) the result.
busongomwembe
30,682 Pointsbusongomwembe
30,682 PointsWe have a bunch of prices and sales numbers and we need to find out our total earnings.
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.
prices = [ (6.99, 5), (2.94, 15), (156.99, 2), (99.99, 4), (1.82, 102) ] def product_sale(single_two): price,units=single_two return price* units print(reduce(product_sale,prices))
NB why not working too
Steven Parker
231,248 PointsSteven Parker
231,248 PointsTwo issues here: