samedi 28 mars 2015

How can I capitalize a character with an odd-numbered index in a string?

So I was doing our exercise when I came across capitalizing characters in odd indices. I tried this:



for i in word:
if i % 2 != 0:
word[i] = word[i].capitalize()
else:
word[i] = word[i]


However, it ends up showing an error saying that not all strings can be converted. Can you help me debug this code snippet?


Aucun commentaire:

Enregistrer un commentaire