Skip to content

Commit cd71786

Browse files
committed
Little Sister's Essay
1 parent 850102b commit cd71786

File tree

7 files changed

+522
-0
lines changed

7 files changed

+522
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"kimolivia"
4+
],
5+
"contributors": [
6+
"valentin-p",
7+
"BethanyG"
8+
],
9+
"files": {
10+
"solution": [
11+
"string_methods.py"
12+
],
13+
"test": [
14+
"string_methods_test.py"
15+
],
16+
"exemplar": [
17+
".meta/exemplar.py"
18+
]
19+
},
20+
"icon": "anagrams",
21+
"blurb": "Learn about string methods while improving your little sister's school essay."
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"track":"python","exercise":"little-sisters-essay","id":"d7b318f2f60a4c0c8935500301c0d990","url":"https://exercism.org/tracks/python/exercises/little-sisters-essay","handle":"myFirstCode","is_requester":true,"auto_approve":false}

little-sisters-essay/HELP.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
We use [pytest][pytest: Getting Started Guide] as our website test runner.
6+
You will need to install `pytest` on your development machine if you want to run tests for the Python track locally.
7+
You should also install the following `pytest` plugins:
8+
9+
- [pytest-cache][pytest-cache]
10+
- [pytest-subtests][pytest-subtests]
11+
12+
Extended information can be found in our website [Python testing guide][Python track tests page].
13+
14+
15+
### Running Tests
16+
17+
To run the included tests, navigate to the folder where the exercise is stored using `cd` in your terminal (_replace `{exercise-folder-location}` below with your path_).
18+
Test files usually end in `_test.py`, and are the same tests that run on the website when a solution is uploaded.
19+
20+
Linux/MacOS
21+
```bash
22+
$ cd {path/to/exercise-folder-location}
23+
```
24+
25+
Windows
26+
```powershell
27+
PS C:\Users\foobar> cd {path\to\exercise-folder-location}
28+
```
29+
30+
<br>
31+
32+
Next, run the `pytest` command in your terminal, replacing `{exercise_test.py}` with the name of the test file:
33+
34+
Linux/MacOS
35+
```bash
36+
$ python3 -m pytest -o markers=task {exercise_test.py}
37+
==================== 7 passed in 0.08s ====================
38+
```
39+
40+
Windows
41+
```powershell
42+
PS C:\Users\foobar> py -m pytest -o markers=task {exercise_test.py}
43+
==================== 7 passed in 0.08s ====================
44+
```
45+
46+
47+
### Common options
48+
- `-o` : override default `pytest.ini` (_you can use this to avoid marker warnings_)
49+
- `-v` : enable verbose output.
50+
- `-x` : stop running tests on first failure.
51+
- `--ff` : run failures from previous test before running other test cases.
52+
53+
For additional options, use `python3 -m pytest -h` or `py -m pytest -h`.
54+
55+
56+
### Fixing warnings
57+
58+
If you do not use `pytest -o markers=task` when invoking `pytest`, you might receive a `PytestUnknownMarkWarning` for tests that use our new syntax:
59+
60+
```bash
61+
PytestUnknownMarkWarning: Unknown pytest.mark.task - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
62+
```
63+
64+
To avoid typing `pytest -o markers=task` for every test you run, you can use a `pytest.ini` configuration file.
65+
We have made one that can be downloaded from the top level of the Python track directory: [pytest.ini][pytest.ini].
66+
67+
You can also create your own `pytest.ini` file with the following content:
68+
69+
```ini
70+
[pytest]
71+
markers =
72+
task: A concept exercise task.
73+
```
74+
75+
Placing the `pytest.ini` file in the _root_ or _working_ directory for your Python track exercises will register the marks and stop the warnings.
76+
More information on pytest marks can be found in the `pytest` documentation on [marking test functions][pytest: marking test functions with attributes] and the `pytest` documentation on [working with custom markers][pytest: working with custom markers].
77+
78+
Information on customizing pytest configurations can be found in the `pytest` documentation on [configuration file formats][pytest: configuration file formats].
79+
80+
81+
### Extending your IDE or Code Editor
82+
83+
Many IDEs and code editors have built-in support for using `pytest` and other code quality tools.
84+
Some community-sourced options can be found on our [Python track tools page][Python track tools page].
85+
86+
[Pytest: Getting Started Guide]: https://docs.pytest.org/en/latest/getting-started.html
87+
[Python track tools page]: https://exercism.org/docs/tracks/python/tools
88+
[Python track tests page]: https://exercism.org/docs/tracks/python/tests
89+
[pytest-cache]:http://pythonhosted.org/pytest-cache/
90+
[pytest-subtests]:https://github.com/pytest-dev/pytest-subtests
91+
[pytest.ini]: https://github.com/exercism/python/blob/main/pytest.ini
92+
[pytest: configuration file formats]: https://docs.pytest.org/en/6.2.x/customize.html#configuration-file-formats
93+
[pytest: marking test functions with attributes]: https://docs.pytest.org/en/6.2.x/mark.html#raising-errors-on-unknown-marks
94+
[pytest: working with custom markers]: https://docs.pytest.org/en/6.2.x/example/markers.html#working-with-custom-markers
95+
96+
## Submitting your solution
97+
98+
You can submit your solution using the `exercism submit string_methods.py` command.
99+
This command will upload your solution to the Exercism website and print the solution page's URL.
100+
101+
It's possible to submit an incomplete solution which allows you to:
102+
103+
- See how others have completed the exercise
104+
- Request help from a mentor
105+
106+
## Need to get help?
107+
108+
If you'd like help solving the exercise, check the following pages:
109+
110+
- The [Python track's documentation](https://exercism.org/docs/tracks/python)
111+
- The [Python track's programming category on the forum](https://forum.exercism.org/c/programming/python)
112+
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
113+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
114+
115+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
116+
117+
Below are some resources for getting help if you run into trouble:
118+
119+
- [The PSF](https://www.python.org) hosts Python downloads, documentation, and community resources.
120+
- [The Exercism Community on Discord](https://exercism.org/r/discord)
121+
- [Python Community on Discord](https://pythondiscord.com/) is a very helpful and active community.
122+
- [/r/learnpython/](https://www.reddit.com/r/learnpython/) is a subreddit designed for Python learners.
123+
- [#python on Libera.chat](https://www.python.org/community/irc/) this is where the core developers for the language hang out and get work done.
124+
- [Python Community Forums](https://discuss.python.org/)
125+
- [Free Code Camp Community Forums](https://forum.freecodecamp.org/)
126+
- [CodeNewbie Community Help Tag](https://community.codenewbie.org/t/help)
127+
- [Pythontutor](http://pythontutor.com/) for stepping through small code snippets visually.
128+
129+
Additionally, [StackOverflow](http://stackoverflow.com/questions/tagged/python) is a good spot to search for your problem/question to see if it has been answered already.
130+
If not - you can always [ask](https://stackoverflow.com/help/how-to-ask) or [answer](https://stackoverflow.com/help/how-to-answer) someone else's question.

little-sisters-essay/HINTS.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Hints
2+
3+
## General
4+
5+
- [Python Documentation: String Methods][string-method-docs]
6+
- [Python Documentation Tutorial: Text][tutorial-strings]
7+
8+
## 1. Capitalize the title of the paper
9+
10+
- You can use [string methods][title-method-docs] to capitalize the title properly.
11+
12+
## 2. Check if each sentence ends with a period
13+
14+
- You can use [string methods][endswith-method-docs] to check the ending of a string.
15+
16+
## 3. Clean up spacing
17+
18+
- You can use [string methods][strip-method-docs] to remove whitespace.
19+
20+
## 4. Replace words with a synonym
21+
22+
- You can use [string methods][replace-method-docs] to replace words.
23+
24+
[endswith-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.endswith
25+
[replace-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.replace
26+
[string-method-docs]: https://docs.python.org/3/library/stdtypes.html#string-methods
27+
[strip-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.strip
28+
[title-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.title
29+
[tutorial-strings]: https://docs.python.org/3/tutorial/introduction.html#text

little-sisters-essay/README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Little Sister's Essay
2+
3+
Welcome to Little Sister's Essay on Exercism's Python Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
6+
7+
## Introduction
8+
9+
The `str` class offers [many useful methods][str methods] for working with and composing strings.
10+
These include searching, cleaning, splitting, transforming, translating, and many other techniques.
11+
12+
Strings are [immutable sequences][text sequence] of [Unicode code points][unicode code points] -- individual "characters" or code points (_strings of length 1_) can be referenced by `0-based index` number from the left, or `-1-based index` number from the right.
13+
14+
Strings can be iterated through using `for item in <str>` or `for index, item in enumerate(<str>)` syntax.
15+
They can be concatenated using the `+` operator or via `<string>.join(<iterable>)` and implement all [common sequence operations][common sequence operations].
16+
17+
Strings are _immutable_, meaning the value of a `str` object in memory cannot change.
18+
Functions or methods that operate on a `str` (_like the ones we are learning about here_) will return a new `instance` of that `str` object instead of modifying the original `str`.
19+
20+
Following is a small selection of Python string methods.
21+
For a complete list, see the [str class][str methods] in the Python docs.
22+
23+
24+
[`<str>.title()`][str-title] parses a string and capitalizes the first "character" of each "word" found.
25+
In Python, this is very dependent on the [language codec][codecs] used and how the particular language represents words and characters.
26+
There may also be [locale][locale] rules in place for a language or character set.
27+
28+
29+
```python
30+
man_in_hat_th = 'ผู้ชายใส่หมวก'
31+
man_in_hat_ru = 'мужчина в шляпе'
32+
man_in_hat_ko = '모자를 쓴 남자'
33+
man_in_hat_en = 'the man in the hat.'
34+
35+
>>> man_in_hat_th.title()
36+
'ผู้ชายใส่หมวก'
37+
38+
>>> man_in_hat_ru.title()
39+
'Мужчина В Шляпе'
40+
41+
>>> man_in_hat_ko.title()
42+
'모자를 쓴 남자'
43+
44+
>> man_in_hat_en.title()
45+
'The Man In The Hat.'
46+
```
47+
48+
[`<str>.endswith(<suffix>)`][str-endswith] returns `True` if the string ends with `<suffix>`, `False` otherwise.
49+
50+
51+
```python
52+
>>> 'My heart breaks. 💔'.endswith('💔')
53+
True
54+
55+
>>> 'cheerfulness'.endswith('ness')
56+
True
57+
58+
# Punctuation is part of the string, so needs to be included in any endswith match.
59+
>>> 'Do you want to 💃?'.endswith('💃')
60+
False
61+
62+
>> 'The quick brown fox jumped over the lazy dog.'.endswith('dog')
63+
False
64+
```
65+
66+
[`<str>.strip(<chars>)`][str-strip] returns a copy of the `str` with leading and trailing `<chars>` removed.
67+
The code points specified in `<chars>` are not a prefix or suffix - **all combinations** of the code points will be removed starting from **both ends** of the string.
68+
If nothing is specified for `<chars>`, all combinations of whitespace code points will be removed.
69+
70+
71+
```python
72+
# This will remove "https://", because it can be formed from "/stph:".
73+
>>> 'https://unicode.org/emoji/'.strip('/stph:')
74+
'unicode.org/emoji'
75+
76+
# Removal of all whitespace from both ends of the str.
77+
>>> ' 🐪🐪🐪🌟🐪🐪🐪 '.strip()
78+
'🐪🐪🐪🌟🐪🐪🐪'
79+
80+
>>> justification = 'оправдание'
81+
>>> justification.strip('еина')
82+
'оправд'
83+
84+
# Prefix and suffix in one step.
85+
>>> 'unaddressed'.strip('dnue')
86+
'address'
87+
88+
>>> ' unaddressed '.strip('dnue ')
89+
'address'
90+
```
91+
92+
93+
[`<str>.replace(<substring>, <replacement substring>)`][str-replace] returns a copy of the string with all occurrences of `<substring>` replaced with `<replacement substring>`.
94+
95+
The quote used below is from [The Hunting of the Snark][The Hunting of the Snark] by [Lewis Carroll][Lewis Carroll]
96+
97+
```python
98+
# The Hunting of the Snark, by Lewis Carroll
99+
>>> quote = '''
100+
"Just the place for a Snark!" the Bellman cried,
101+
As he landed his crew with care;
102+
Supporting each man on the top of the tide
103+
By a finger entwined in his hair.
104+
105+
"Just the place for a Snark! I have said it twice:
106+
That alone should encourage the crew.
107+
Just the place for a Snark! I have said it thrice:
108+
What I tell you three times is true."
109+
'''
110+
111+
>>> quote.replace('Snark', '🐲')
112+
...
113+
'\n"Just the place for a 🐲!" the Bellman cried,\n As he landed his crew with care;\nSupporting each man on the top of the tide\n By a finger entwined in his hair.\n\n"Just the place for a 🐲! I have said it twice:\n That alone should encourage the crew.\nJust the place for a 🐲! I have said it thrice:\n What I tell you three times is true."\n'
114+
115+
>>> 'bookkeeper'.replace('kk', 'k k')
116+
'book keeper'
117+
```
118+
119+
[Lewis Carroll]: https://www.poetryfoundation.org/poets/lewis-carroll
120+
[The Hunting of the Snark]: https://www.poetryfoundation.org/poems/43909/the-hunting-of-the-snark
121+
[codecs]: https://docs.python.org/3/library/codecs.html
122+
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
123+
[locale]: https://docs.python.org/3/library/locale.html#module-locale
124+
[str methods]: https://docs.python.org/3/library/stdtypes.html#string-methods
125+
[str-endswith]: https://docs.python.org/3/library/stdtypes.html#str.endswith
126+
[str-replace]: https://docs.python.org/3/library/stdtypes.html#str.replace
127+
[str-strip]: https://docs.python.org/3/library/stdtypes.html#str.strip
128+
[str-title]: https://docs.python.org/3/library/stdtypes.html#str.title
129+
[text sequence]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
130+
[unicode code points]: https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme
131+
132+
## Instructions
133+
134+
In this exercise you are helping your younger sister edit her paper for school. The teacher is looking for correct punctuation, grammar, and excellent word choice.
135+
136+
You have four tasks to clean up and modify strings.
137+
138+
## 1. Capitalize the title of the paper
139+
140+
Any good paper needs a properly formatted title.
141+
Implement the function `capitalize_title(<title>)` which takes a title `str` as a parameter and capitalizes the first letter of each word.
142+
This function should return a `str` in title case.
143+
144+
145+
```python
146+
>>> capitalize_title("my hobbies")
147+
"My Hobbies"
148+
```
149+
150+
## 2. Check if each sentence ends with a period
151+
152+
You want to make sure that the punctuation in the paper is perfect.
153+
Implement the function `check_sentence_ending()` that takes `sentence` as a parameter. This function should return a `bool`.
154+
155+
156+
```python
157+
>>> check_sentence_ending("I like to hike, bake, and read.")
158+
True
159+
```
160+
161+
## 3. Clean up spacing
162+
163+
To make the paper look professional, unnecessary spacing needs to be removed.
164+
Implement the function `clean_up_spacing()` that takes `sentence` as a parameter.
165+
The function should remove extra whitespace at both the beginning and the end of the sentence, returning a new, updated sentence `str`.
166+
167+
168+
```python
169+
>>> clean_up_spacing(" I like to go on hikes with my dog. ")
170+
"I like to go on hikes with my dog."
171+
```
172+
173+
## 4. Replace words with a synonym
174+
175+
To make the paper _even better_, you can replace some of the adjectives with their synonyms.
176+
Write the function `replace_word_choice()` that takes `sentence`, `old_word`, and `new_word` as parameters.
177+
This function should replace all instances of the `old_word` with the `new_word`, and return a new `str` with the updated sentence.
178+
179+
180+
```python
181+
>>> replace_word_choice("I bake good cakes.", "good", "amazing")
182+
"I bake amazing cakes."
183+
```
184+
185+
## Source
186+
187+
### Created by
188+
189+
- @kimolivia
190+
191+
### Contributed to by
192+
193+
- @valentin-p
194+
- @BethanyG

0 commit comments

Comments
 (0)