Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Please help me understand this question

One argument i have to take is it the list Or i just have to return the list

instances.py
def combiner(self):
    return print(["apple" + 7.9 + "snake" + 9])

1 Answer

Ken Stone
Ken Stone
29,702 Points

You need to create a function that accepts a list

Here the params parameter is a list

then for each item in the list determine if it's a string or a number

If it's a sting concat it with the other strings

if a number add it to the total

then finally return the concat of the string with the number coerced as a string

def combiner(params):
  ret_val = ''
  total = 0

  for param in params:
    if(isinstance(param, str)):
      ret_val += param
    else:
      total += param

  return ret_val + str(total)