Python

Kayvon Wallace
Kayvon Wallace
14,629 Points

i don't understand why this wont pass.

This took me three days to get this to work, but still not passing on the actually test, and i don't know why. i've tried different inputs, and i'm always getting back string seperated with nothing, then sum of my number list.....please help.

instances.py
def combiner(items) :
    string = []    
    number = []
    s = ""
    for item in items:
        if isinstance(item, str) == True:
            string.append(item)
        elif isinstance(item, int) == True:
            number.append(item)  
    string = s.join(string)
    combined = f"{string}{sum(number)}"
    return combined

2 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,332 Points

You also need to consider floats

Kayvon Wallace
Kayvon Wallace
14,629 Points

def combiner(items) : string = []
number = [] s = "" for item in items: if isinstance(item, str) == True: string.append(item) elif isinstance(item, (int, float)) == True: number.append(item)
string = s.join(string) combined = f"{string}{sum(number)}" return combined

fixed it about 2 seconds ago. was trying to update. lol

Kayvon Wallace
Kayvon Wallace
14,629 Points

Thanks, that answer was spot on thought. Ended up testing with a float. notice it was getting out throw out cause of elif. researched how to add to arg in to isinstance, then bing bang boom!!

This site help my code too for whoever else this my help.
https://www.programiz.com/python-programming/methods/built-in/isinstance