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 trialsai d
128 Pointstuples multiply,slice
Let's play with the *args pattern. Create a function named multiply that takes any number of arguments. Return the product (multiplied value) of all of the supplied arguments. The type of argument shouldn't matter. Slices might come in handy for this one.
def multiply( args): pro=1 for v in args: pro=v return pro multiply(3,5)
HERE I DID'NT USE ANY SLICES BUT THE TASK WAS COMPLETED WHY?
1 Answer
Steven Parker
231,275 PointsThe instructions said "Slices might come in handy for this one." But there are many ways to get the same result, and only some of them would use slices.
Your solution is effective and concise. Good job!
Jimmy Otis
3,228 PointsJimmy Otis
3,228 PointsSteven, I too came out with the same code as the poster of this question. However I am curious, how would one utilize slices to reach the same result?
Steven Parker
231,275 PointsSteven Parker
231,275 PointsInstead of starting with 1 and then multipying it by each element, you could also start with the first item and then multiply by each of the others. A slice could be used to make a list containing all the items after the first.