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 trialAshley Keeling
11,476 PointsI am not sure why this function wont work
I don't know why , and it looks similar to the add function in the video
def multiply(*args):
nums=*args
total = 0
for num in nums:
total = num * num
return total
mattmcknight
3,155 Pointsyour total is going to be the last number in the list of *args squared. Also your total is set to 0 so if you fix the first problem, your total will always be 0.
1 Answer
Steven Parker
231,275 PointsHere's some hints:
- you don't need "nums", you can iterate using "args"
- the "total" needs to be the result of multiplying all numbers together, not just the square of one of them
- you might need to start total with 1 instead of 0
Ashley Keeling
11,476 Pointshow do you multiply the numbers together instead of squaring them
Steven Parker
231,275 PointsFor each item in the loop, you might multiply it by the previous total and store it back into the total:
total = 1 # start with 1 because "0 * anything" is still 0
for num in args:
total *= num # this is the same as "total = total * num"
Ashley Keeling
11,476 Pointsthanks I passed the challenge now!!
Myers Carpenter
6,421 PointsMyers Carpenter
6,421 PointsI think your problem is this line.
nums=*args
Maybe you want
=
?You could also rename
args
tonums
, and remove this line. There is nothing special about the nameargs
, only the*
in front of it.