Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion practice/raindrops/raindrops.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
def convert(number):
pass
"""
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:
sounds.append('Plang')
if number % 7 == 0:
sounds.append('Plong')

if len(sounds) == 0:
return str(number)
else:
return "".join(sounds)