First, don't call your variable list
. It is a Python built-in type and using the name for something else it will cause you baffling problems.
To start with, this
word = str(input())
list = []
for i in range(len(word)):
B = word[i]
list.append(B)
is a very cumbersome way to turn a string into a list. Do it this way instead:
>>> word = "fred"
>>> mylist = list(word)
>>> mylist
['f', 'r', 'e', 'd']
To capitalize each word in the list, don't use pop()
because it changes the length of the list, and your expression range(0, len(list))
assumes the length won't change. There is no need to extract your letter from the list in order to build up capitalized_word
:
>>> capitalized_word = ""
>>> for c in mylist:
capitalized_word += c
>>> capitalized_word
'fred'
You will note that this is in fact not capitalized because your code doesn't actually upshift it. To achieve that,
>>> capitalized_word = ""
>>> for c in mylist:
capitalized_word += c.upper()
>>> capitalized_word
'FRED'
This shows you why your method isn't working, but it is not the best approach to working with strings in Python. Don't actually do it this way. Use built-in facilities instead:
>>> word = "fred"
>>> capitalized_word = word.upper()
>>> capitalized_word
'FRED'
Similiarly, don't do this to provide an initial capital:
D = list.pop(0)
E = D.upper()
list.insert(0, E)
Instead do this:
>>> word = "fred"
>>> capitalized_word = word.title()
>>> capitalized_word
'Fred'