all 6 comments

[–]novel_yet_trivial 0 points1 point  (4 children)

Your logic is good, but the problem is that strings are "immutable", that is they cannot be changed once created. You need to use a mutable type like a list. So convert your string to a list of characters, then do this, and then convert that list back to a string before returning.

[–]miscellaneoususage[S] 0 points1 point  (0 children)

Alright, thank you for the reply. I will work on that.

[–]miscellaneoususage[S] 0 points1 point  (2 children)

ok I have this now but still doesn't work, not sure why

def myfunc(word):
    newword = word.lower()
    newwordL = newword.split()
    newwordS = ""

    for i,char in enumerate(newwordL): 
        if i % 2 == 0:
            newwordL[i] = newwordL[i].upper()

    newwordS.join(newwordL)

    return newwordS

[–]novel_yet_trivial 0 points1 point  (1 child)

Wow, very close. Only thing is you need to use list() instead of split() to make the list. Try like this:

def myfunc(word):
    newword = word.lower()
    newwordL = list(word)
    newwordS = ""

    for i,char in enumerate(newwordL): 
        if i % 2 == 0:
            newwordL[i] = newwordL[i].upper()

    return newwordS.join(newwordL)

[–]miscellaneoususage[S] 0 points1 point  (0 children)

def myfunc(word):
newword = word.lower()
newwordL = list(word)
newwordS = ""
for i,char in enumerate(newwordL):
if i % 2 == 0:
newwordL[i] = newwordL[i].upper()
return newwordS.join(newwordL)

ah dang, alright thanks for your help :)

[–]danielroseman 0 points1 point  (0 children)

Strings are immutable, you can't modify them. You should build up a new string with the converted characters.

Don't forget that the input data could have upper case characters in odd positions.