forked from reingart/exercism
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
703fe69
commit 6976aa2
Showing
1 changed file
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
def convert(number): | ||
sounds =[] | ||
if number%3==0: | ||
""" | ||
Convert a number into a string that contains raindrop sounds corresponding to certain potential factors. | ||
A factor is a number that evenly divides into another number, leaving no remainder. | ||
The simplest way to test if one number is a factor of another is to use the modulo operation. | ||
The rules of raindrops are that if a given number: | ||
- has 3 as a factor, add 'Pling' to the result. | ||
- has 5 as a factor, add 'Plang' to the result. | ||
- has 7 as a factor, add 'Plong' to the result. | ||
- does not have any of 3, 5, or 7 as a factor, the result should be the digits of the number. | ||
Args: | ||
number (int): The number to be converted into a raindrop sound string. | ||
Returns: | ||
str: The resulting raindrop sound string. | ||
Examples: | ||
>>> convert(28) | ||
'Plong' | ||
>>> convert(30) | ||
'PlingPlang' | ||
>>> convert(34) | ||
'34' | ||
""" | ||
sounds = [] | ||
|
||
if number % 3 == 0: | ||
sounds.append('Pling') | ||
if number%5==0: | ||
if number % 5 == 0: | ||
sounds.append('Plang') | ||
if number%7==0: | ||
if number % 7 == 0: | ||
sounds.append('Plong') | ||
if len(sounds)==0: | ||
|
||
if len(sounds) == 0: | ||
return str(number) | ||
else: | ||
return "".join(sounds) | ||
|
||
return "".join(sounds) |