I am trying to manipulate a word by upper casing each character in an array, but when it comes to a word that has two of the same character it makes them both capitalized instead of just one. Not a programmer just trying to learn python. Thank in advance!
answer = raw_input("What is your word? ")
x = 0
answerWord = ''.join(answer)
while (x < len(answer)):
if (answerWord[x] != answerWord[x].upper()):
letter = answerWord.replace(answer[x], answer[x].upper())
print letter
x = x + 1
What is your word? boot
Boot
bOOt
bOOt
booT
What is your word? crazy
Crazy
cRazy
crAzy
craZy
crazY
That should do the thing, it changes every letter to upper case one by one, and then prints them. Also, in your example, if you take a word that already has uppercase letters (‘Peanuts’, for example) it will raise an error, since the the “if” sentence is not True, and therefore
letterwould be undefined.If you want uppercase letters to go lowercase, and lowercase letters to go uppercase, or such, use this:
Also note, that if you’re not going to use
letterfor anything other than printing it, you could just replace both of the letter definitions with simply a print, and remove theprint lettercompletely.