You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.0 KiB

## Punishment
### Instructions
Often in schools we are asked to copy hundreds of sentences in order to better remember not to do something, this punishment is very old and quite boring!
Hopefully we now have Python that can do the job for us.
In order to do so create a file `punishment.py` which will contain a function `do_punishment` having 3 arguments:
- `first_part`: which will be a string.
- `second_part`: which will be also a string.
- `nb_lines`: which will be a number.
Here is the prototype of the function:
```python
def do_punishment(first_part, second_part, nb_lines):
```
The function will concatenate `first_part` and `second_part`, adding a space in between them and a `.` at the end of `second_part`. It will repeat this process for `nb_lines` times.
The function will return a single string containing all the repeated sentences.
> In case `first_part` and `second_part` have empty spaces at the start or at the end those spaces should be trimmed (removed from the strings).
### Usage
Here is a possible `test.py` to test your functions:
```python
import punishment
print(punishment.do_punishment(' The first half ', ' and the second ', 4), end='')
print(punishment.do_punishment('Will not', 'show', 0), end='')
print(punishment.do_punishment('', '', 3), end='')
```
```bash
$ python test.py
The first half and the second.
The first half and the second.
The first half and the second.
The first half and the second.
.
.
.
```
### Hints
- Removing spaces at the start and end of a string is so common that almost all languages implement this feature. Here you can check for the `strip()` method.
- Instead of using loops you can try the `string multiplication` operator, which is a very nice feature of Python and will make your code more readable.
### References
* [strip](https://www.w3schools.com/python/ref_string_strip.asp)
* [string multiplication](https://www.geeksforgeeks.org/create-multiple-copies-of-a-string-in-python-by-using-multiplication-operator/)