Skip to content

Commit 09e35a0

Browse files
[Sync Iteration] python/little-sisters-essay/2
1 parent 86ba70a commit 09e35a0

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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,
21+
False otherwise.
22+
"""
23+
24+
return sentence[-1] in ".!?"
25+
26+
27+
def clean_up_spacing(sentence: str) -> str:
28+
"""
29+
Verify that there isn't any whitespace at the start and end of the
30+
sentence.
31+
32+
:param sentence: str - a sentence to clean of leading and trailing
33+
space characters.
34+
:return: str - a sentence that has been cleaned of leading and
35+
trailing space characters.
36+
"""
37+
38+
return sentence.strip()
39+
40+
41+
def replace_word_choice(sentence: str, old_word: str, new_word: str) -> str:
42+
"""
43+
Replace a word in the provided sentence with a new one.
44+
45+
:param sentence: str - a sentence to replace words in.
46+
:param old_word: str - word to replace.
47+
:param new_word: str - replacement word.
48+
:return: str - input sentence with new words in place of old words.
49+
"""
50+
51+
return sentence.replace(old_word, new_word)

0 commit comments

Comments
 (0)