We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
print(input().title()) will not work because the question is asking to capitalise firse letter of each word keeping in mind that "if it is a letter". Title and Capitalise are different in function as:
'abcd'.title()
results in 'Abcd'
but
'12abcd'.title()
results in '12Abcd'. This is not what we want.
We just want to capitalise first letter of each word, not the first occuring letter of a word.
Instead, use this:
s = input()
for x in s[:].split():
s = s.replace(x, x.capitalize())
print(s)
Capitalize!
You are viewing a single comment's thread. Return to all comments →
Python 3
print(input().title())
will not work because the question is asking to capitalise firse letter of each word keeping in mind that "if it is a letter". Title and Capitalise are different in function as:results in
results in'Abcd'
but'12Abcd'
. This is not what we want.We just want to capitalise first letter of each word, not the first occuring letter of a word.
Instead, use this: