EasyPython
String Methods — Clean and Format
PythonStrings
Implement solve(sentence) that:
1. Strips leading/trailing whitespace from the sentence.
2. Capitalizes the first letter of each word (title case).
3. Replaces every occurrence of the word "bad" (case-insensitive) with "good".
4. Returns the resulting string.
Examples
solve(" hello world ")→"Hello World"solve("this is bad")→"This Is Good"solve(" BAD habits are bad ")→"Good Habits Are Good"
Constraints
- Words are separated by single spaces after stripping.
- The replacement is case-insensitive but the result must always be lowercase
"good".
Sample tests
Test #1Strip and title case
Input: [" hello world "]
Output: "Hello World"
Test #2Replace bad lowercase
Input: ["this is bad"]
Output: "This Is Good"
Test #3Replace multiple bad words, strip
Input: [" BAD habits are bad "]
Output: "Good Habits Are Good"
Test #4No replacement needed
Input: ["python is great"]
Output: "Python Is Great"