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 trialDuarte Reis
Python Web Development Techdegree Student 3,402 PointsCouldn't multiply valid values together
Shouldn't this work?
We get every num in args and always multiply by the previous total
I'm also confused with other aspect of the challenge. If the variable type does not matter, what happens if the tupple has 2 strings together? We can't multiply them, right? How do we solve this?
Should we control for the error and write the code in a way that we can separate strings from ints?
Thanls in advance!
Duarte
def multiply (base,*args):
total = base
for num in args:
total = total*num
1 Answer
Stuart Wright
41,120 PointsYour code is fine - you just forgot to return total!
In a real life scenario you probably would want some kind of input validation to ensure that only numbers are accepted as arguments, but for the purposes of this challenge it is fine to assume that only numbers will be passed. Passing a tuple that includes other data types could indeed cause an error.
Duarte Reis
Python Web Development Techdegree Student 3,402 PointsDuarte Reis
Python Web Development Techdegree Student 3,402 PointsUps! Thanks a lot! Over confidence!
And thanks for the clarification on my other doubt.
Best!
Duarte