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 trialcorincraciun
2,235 Pointsinstances challenge oop python --> not expected output?
The code has the expected output in my interpreter, but i get error when i try to complete it in the challenge.
def combiner(*args):
strings = ""
numbers = 0
for item in list(args):
if isinstance(item, str):
strings += item
if isinstance(item, (float, int)):
numbers += item
return strings + str(numbers)
1 Answer
KRIS NIKOLAISEN
54,972 PointsThe parameter for the function is a single list. I added the following to your code:
def combiner(*args):
strings = ""
numbers = 0
for item in list(args):
if isinstance(item, list):
print("i am a list")
if isinstance(item, str):
strings += item
if isinstance(item, (float, int)):
numbers += item
return strings + str(numbers)
print(combiner(["apple", 1]))
print(combiner(["apple", 5.2, "dog", 8]))
The result is:
i am a list
0
i am a list
0
corincraciun
2,235 Pointscorincraciun
2,235 PointsNow i noticed that i should have put a single argument, a list. so the correct code should have been. Thank you for the clarifications!