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 trialdevante wallace
5,151 PointsMy code works in the workshop but not in the question?
Please could you advise on what i need to change
strings = []
nums = []
def combiner(*args):
for val in args:
if isinstance(val, str):
strings.append(val)
elif isinstance(val, (int, float)):
nums.append(val)
total = "".join(strings) + (str(sum(nums)))
return total
1 Answer
KRIS NIKOLAISEN
54,971 PointsAs a test try the example given in the challenge:
print(combiner(["apple", 5.2, "dog", 8]))
The result should be appledog13.2
. The result of your function is 0
.
Tlotlo Molokwe
16,618 PointsTlotlo Molokwe
16,618 PointsYou have to initialize your variables within your function and the variables themselves can't be lists so set them as an empty string and give your int variable a 0 default value like:
the rest of your code should look something like:
instead of using append the variables will be seperated depending on their type and then added together by using += the return statement then joins back the separated variables to make one string or you could assign total:
total = strings + str(nums)
and return total like you did in your code