Closed cogginproductions closed 7 years ago
I'm with you on this, @cogginproductions. From the challenge question in my version of the book, I thought the answer was:
"aldous Huxley was born in 1894.".capitalize()
but the code returned:
'Aldous huxley was born in 1894.'
What gives?
Thanks for the feedback. I am looking into this now.
@ILeftTheLaw @cogginproductions I didn't even realize this is the repository for the old version of the book. Please email me so I can get you the latest version. This problem should be resolved there. Very sorry about that.
@cogginproductions @ILeftTheLaw I looked into this. You both are correct. capitalize() returns a new string and makes the rest of the string lowercase. I forgot that it also makes everything else in the string lowercase. I will change this example. Thanks so much for pointing this out. In the meantime, here is one way you could solve the challenge:
def upperfirst(string):
return string[0].upper() + string[1:]
print(upperfirst("aldous Huxley was born in 1894."))
You're welcome and thank you. I will give it a try. Glad I can help out!
In the book you talk about using capitalize() for capitalizing the first letter of a sentence, but in the solution file you show using title(). And in the challenge question you have "Huxley" with a capital "H" but in the solution its lower case.
Now when I use capitalize, it makes the first letter of the sentence capital but makes every other words first letter lower case (i.e. "aldous Huxley was born in 1984." becomes "Aldous huxley was born in 1984.").
Then when I use title(), "aldous Huxley was born in 1984." becomes "Aldous Huxley Was Born In 1984."
I'm a little confused on what's going on....