Python Object-Oriented Python Inheritance Instances

Blessing Nyamayedenga
Blessing Nyamayedenga
6,202 Points

instances challenge

hey guys im not sure what im doing wrong here ,please help

instances.py
def combiner(str_num):
    mixed_list = ["mom", "eldrine", "kiki",8, 5, 8, 5, 2, 3]
    str_num = []
    nums = 0
    strings = []
    for item in mixed_list:
        if isinstance(item, str):
            strings.join(item)
        else:
            nums += item
             str_nums = strings.join(str,nums)
    return str_num      

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 58,896 Points

You are very close. Here are the items to fix:

  • the for item loop should loop over the str_num argument, not the static test value mixed_list
  • use strings.append instead of strings.join. A list object has no join method
  • use "".join(strings) to get the strings into one string
  • use str(nums) to get the numbers into a string
  • You can use + to combine these in the return statement.
  • the str_nums assignment should be outside of the for loop

Post back if you need more help. Good luck!!

Blessing Nyamayedenga
Blessing Nyamayedenga
6,202 Points

here is what I did but im still getting a bummer saying didn't get expected result

def combiner(str_num): str_num = ["mom", "eldrine", "kiki",8, 5, 8, 5, 2, 3] nums = [] strings = [] for item in str_num: if isinstance(item, str): strings.append(item) elif isinstance(item,(int,float)): nums.append(item) nums = sum(nums) strings = "".join(strings)
return strings + str(nums)