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 trialdavie Rombedza
1,288 Pointsmy code works in the pycharm bu wont work here why
i run the same code in jupyter and it worked
dimensions = [
(5, 5),
(10, 10),
(2.2, 2.3),
(100, 100),
(8, 70),
]
def area(dimensions):
products=[]
for x in dimensions:
product = 1
for element in x:
product *= element
products.append(product)
return tuple(products)
#print(area(dimensions))
1 Answer
Steven Parker
231,275 PointsI'd guess you've misinterpreted the instructions, which is easy to do when you work on challenges in an external REPL or IDE. Then it seems like it "works", but it's doing something different from the requirements.
The instructions tell you that the argument "will be a two-member tuple". Your implementation of looping through any number of elements is fancier than needed, yet could still work. But the code is also trying to loop through each individual element (loop within a loop), but since the elements are just numbers they cannot be used as iterators. You were probably thinking the function would process the entire list of sample data at once, but that's not what they are asking for.
The instructions also ask you to "return the result of multiplying the first item ... by the second item". But the code is building a list and returning it as a tuple, when all you need to return is the single product value.
Give it another shot, and I'll bet you get it this time.