I want Python to take a string and iterate through it, printing several variations with an individual letter capitalized. Like this:
Input:
"hello world"
Output:
"Hello world", "hEllo world", "heLlo world", etc.
Here's what I have so far:
string = "hello world".lower()
for x in range(0, len(string)):
new_string = string[:(x-1)].lower() + string[x].capitalize() + string[(x-1):].lower()
print(new_string)
However, this code spits out some pretty funky looking strings:
hello worlHd
Ehello world
hLello world
etc.
I suspect my issue has something to do with the way I'm indexing the string, but I'm not sure what to change. Any ideas?
new_string = string[:x].lower() + string[x].upper() + string[x+1:].lower()reprso that you can see quotes around the strings, to highlight empty strings,whitespace etc.)