Python
Programming Exercises, Gently Explained
109
Special Cases and Gotchas
Title case not only means the first letter is in uppercase, but all other letters must be lowercase.
It’s not enough to only make the first letter uppercase. You must also force the remaining
letters to be
lowercase. Converting the string 'mcCloud' to title case doesn’t result in 'McCloud' but rather
'Mccloud'
.
There is also a boundary condition you should be aware of when looking at the ―previous index‖
in the for loop. You can easily calculate the previous index from the index i with the expression i -
1
, but there’s a catch: when i is 0, this results in -1 which refers to the last index of the string. Your
code must explicitly make sure you aren’t checking the previous index for the first
index of the string,
because there is no previous index in that case.
Now try to write a solution based on the information in the previous sections. If you still have
trouble solving this exercise,
read the Solution Template section for additional hints.
Dostları ilə paylaş: