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 trialsameer Alikhil
1,190 Pointsmerging of strings and integers
I still don't understand why my code is wrong. I know that instead of else in if-else-statement, I could have used the following code to exclude boolean values:
elif isinstance(item, str): list_words.append(item)
But in the question is mentioned that the argument of the function will only consist of strings and numbers. That's why I've used the 'else statement'..
The code works just fine when I run in Atom, but somehow in workspace it doesn't do anything.
What am I doing wrong here?
def combiner(arg):
list_numbers = []
list_words = []
for item in arg:
if isinstance(item, (int, float)):
list_numbers.append(item)
else:
list_words.append(item)
sum_numbers = sum(list_numbers)
merged_words = "".join(list_words)
print(merged_words + str(sum_numbers))
2 Answers
Mark Kastelic
8,147 PointsYou got this Sameer. It's just that the challenge insists on seeing a return statement instead of print.
KRIS NIKOLAISEN
54,972 PointsMark is right and with that change you will pass the challenge. But try the following:
combiner(["apple", 5.2, "dog", 8, "\n"])
combiner(["apple", 5.2, "dog", 8, "\", "n"])
combiner(["apple", 5.2, "dog", 8, "n", "\"])
combiner(["\r"])
sameer Alikhil
1,190 Pointssameer Alikhil
1,190 PointsThank you for your response. It worked :)