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 trialAnthony Longo
1,801 PointsI know I'm doing something wrong.
I know I'm doing something wrong, I just don't know what. when I run this in workplace I get the right answer but when I try and check it, it says Bummer: didn't get the expected answer.
def combiner(*arg):
num = []
stringL = []
strings = ""
for item in arg:
if isinstance(item,(int,float)):
num.append(item)
elif isinstance(item,str):
stringL.append(item)
for items in stringL:
strings += items
return str("{}{}".format(strings,sum(num)))
1 Answer
KRIS NIKOLAISEN
54,971 PointsThe challenge passes in a single list. By using *arg as a parameter you iterate the list as a whole instead of the items within the list. As such item is not an instance of int, float or string. It is an instance of a list. Remove the * so you just have def combiner(arg):
You can test this in a workspace with a print statement
def combiner(*arg): # try both arg and *arg
num = []
stringL = []
strings = ""
for item in arg:
print(item) # add this
if isinstance(item,(int,float)):
num.append(item)
elif isinstance(item,str):
stringL.append(item)
elif isinstance(item, list):
print("I'm a list")
for items in stringL:
strings += items
return str("{}{}".format(strings,sum(num)))
print(combiner(["apple", 5.2, "dog", 8]))
Son-Hai Nguyen
2,481 PointsSon-Hai Nguyen
2,481 PointsReally? I found this on the internet, and I thought it's pretty the same as what we're trying to do here
So, the challenge passed on a list technically because it was setup that way right? I mean in normal situation I'd to add in as
combiner("apple", 5.2, "dog", 8)
. The hard brackets feel a bit over-typo to me