Skip to content

Commit 82639e1

Browse files
[Sync Iteration] python/little-sisters-essay/1
1 parent 850102b commit 82639e1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Functions to help edit essay homework using string manipulation."""
2+
3+
4+
def capitalize_title(title: str) -> str:
5+
"""
6+
Convert the first letter of each word in the title to uppercase if needed.
7+
8+
:param title: str - title string that needs title casing.
9+
:return: str - title string in title case (first letters capitalized).
10+
"""
11+
12+
return title.title()
13+
14+
15+
def check_sentence_ending(sentence: str) -> bool:
16+
"""
17+
Check the ending of the sentence to verify that a period is present.
18+
19+
:param sentence: str - a sentence to check.
20+
:return: bool - return True if punctuated correctly with period, False otherwise.
21+
"""
22+
23+
return True if sentence[-1] in ".!?" else False
24+
25+
26+
def clean_up_spacing(sentence: str) -> str:
27+
"""
28+
Verify that there isn't any whitespace at the start and end of the sentence.
29+
30+
:param sentence: str - a sentence to clean of leading and trailing space characters.
31+
:return: str - a sentence that has been cleaned of leading and trailing space characters.
32+
"""
33+
34+
return sentence.strip()
35+
36+
37+
def replace_word_choice(sentence: str, old_word: str, new_word: str) -> str:
38+
"""
39+
Replace a word in the provided sentence with a new one.
40+
41+
:param sentence: str - a sentence to replace words in.
42+
:param old_word: str - word to replace.
43+
:param new_word: str - replacement word.
44+
:return: str - input sentence with new words in place of old words.
45+
"""
46+
47+
return sentence.replace(old_word, new_word)

0 commit comments

Comments
 (0)