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 trial
Kohei Ashida
4,882 PointsI cannot solve the code challenge: instances in python OOP
I stuck on instances coding challenge... Could someone give me the way how to solve this?
def combiner(*args):
words = ""
nums = 0
for item in args:
if isinstance(item, str):
words += item
elif isinstance(item, (int, float)):
nums += item
return words + str(nums)
1 Answer
Scott Bailey
13,190 PointsYour code will pass (if it's the challenge I think it it) if you just change the opening.
def combiner(args):
The challenge is only passing you a single arguement of a list, so you only need to take in one arguement, that you can iterate through.
Full code
def combiner(args):
words = ""
nums = 0
for item in args:
if isinstance(item, str):
words += item
elif isinstance(item, (int, float)):
nums += item
return words + str(nums)
Just playing around - if you wanted to keep *args - the code will work if you slightly change the for loop:
def combiner(*args):
words = ""
nums = 0
for arg in args[0]:
if isinstance(arg, str):
words += arg
elif isinstance(arg, (int, float)):
nums += arg
return words + str(nums)
It's different to how I would have done it (slightly) but it does the job! Good work!
Kohei Ashida
4,882 PointsKohei Ashida
4,882 PointsThanks a lot! It worked out!