Skip to content

Commit

Permalink
python/raindrops: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 9, 2024
1 parent c494d61 commit bbc693a
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
- [leap](./leap/README.md)
- [mecha-munch-management](./mecha-munch-management/README.md)
- [plane-tickets](./plane-tickets/README.md)
- [raindrops](./raindrops/README.md)
1 change: 1 addition & 0 deletions python/raindrops/.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"arcs":{"/home/vpayno/git_vpayno/exercism-workspace/python/raindrops/test/__init__.py":[[0,0],[0,-1]],"/home/vpayno/git_vpayno/exercism-workspace/python/raindrops/raindrops.py":[[0,1],[1,4],[4,-1],[4,11],[11,13],[13,16],[16,19],[19,22],[22,23],[23,25],[25,-4],[13,14],[14,16],[16,17],[17,19],[19,20],[20,22],[22,25]]}}
39 changes: 39 additions & 0 deletions python/raindrops/.coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" ?>
<coverage branch-rate="1" branches-covered="8" branches-valid="8" complexity="0" line-rate="0.9167" lines-covered="11" lines-valid="12" timestamp="1712624760382" version="4.5.4">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/vpayno/git_vpayno/exercism-workspace/python/raindrops</source>
</sources>
<packages>
<package branch-rate="1" complexity="0" line-rate="0.9167" name=".">
<classes>
<class branch-rate="1" complexity="0" filename="raindrops.py" line-rate="0.9167" name="raindrops.py">
<methods/>
<lines>
<line hits="0" number="0"/>
<line hits="1" number="4"/>
<line hits="1" number="11"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="13"/>
<line hits="1" number="14"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="16"/>
<line hits="1" number="17"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="19"/>
<line hits="1" number="20"/>
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="22"/>
<line hits="1" number="23"/>
<line hits="1" number="25"/>
</lines>
</class>
</classes>
</package>
<package branch-rate="1" complexity="0" line-rate="1" name="test">
<classes>
<class branch-rate="1" complexity="0" filename="test/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
</coverage>
2 changes: 2 additions & 0 deletions python/raindrops/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = __init__.py, *_test.py
1 change: 1 addition & 0 deletions python/raindrops/.pylintrc
7 changes: 6 additions & 1 deletion python/raindrops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ The built-in function [`divmod()`][divmod] will also give a remainder than match

### Based on

A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz
A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz

### My Solution

- [my solution](./raindrops.py)
- [run-tests](./run-tests-python.txt)
5 changes: 5 additions & 0 deletions python/raindrops/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
pythonpath = .
addopts = --doctest-modules
markers =
task: exercise task/step
27 changes: 25 additions & 2 deletions python/raindrops/raindrops.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
def convert(number):
pass
"""Raindrops exercism: https://exercism.org/tracks/python/exercises/raindrops"""


def convert(number: int) -> str:
"""Converts a number to the sound of rain drops.
:param number: positive integer
:return: string with rain sounds or the number if it can't be converted
"""

sounds: list[str] = []

if number % 3 == 0:
sounds.append("Pling")

if number % 5 == 0:
sounds.append("Plang")

if number % 7 == 0:
sounds.append("Plong")

if len(sounds) == 0:
sounds.append(f"{number}")

return "".join(sounds)
25 changes: 25 additions & 0 deletions python/raindrops/raindrops.py,cover
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
> """Raindrops exercism: https://exercism.org/tracks/python/exercises/raindrops"""


> def convert(number: int) -> str:
> """Converts a number to the sound of rain drops.

> :param number: positive integer
> :return: string with rain sounds or the number if it can't be converted
> """

> sounds: list[str] = []

> if number % 3 == 0:
> sounds.append("Pling")

> if number % 5 == 0:
> sounds.append("Plang")

> if number % 7 == 0:
> sounds.append("Plong")

> if len(sounds) == 0:
> sounds.append(f"{number}")

> return "".join(sounds)
Loading

0 comments on commit bbc693a

Please sign in to comment.