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 trial

Python Functional Python The Lambda Lambada Reduce

Dmitry Karamin
Dmitry Karamin
10,099 Points

What output should be

i don't get the task argument is a tuple (price, qty) and the result of the func is product of price and qty - what does it mean??

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

2 Answers

Alperen Guman
Alperen Guman
6,552 Points

A tuple is a datatype in python just like lists or dictionaries. It is comprised of some elements x and y in the format (x, y). The task you're given is to create a function that will take a tuple as an argument and in this tuple x will be price and y will be quantity. The function must return the multiplication of x and y.

Example: I'm buying 5 eggs from $2 each. The tuple should be formatted (2, 5). the function should take in the (2,5) which is a single element and return 2*5=10

For further reading on tuples: https://docs.python.org/3/library/stdtypes.html?highlight=tuple#tuple

Dmitry Karamin
Dmitry Karamin
10,099 Points

so what the problem with this solution? def product_sales(args): return args[0][0]*args[0][1]

are you sure that the result should be multiplication?

Alperen Guman
Alperen Guman
6,552 Points

A tuple is a single immutable element. I'm sure about the multiplication.

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

Above revision should work.

Loop over your tuples in your list with a for loop as needed.